JAVA Code Generation in Eclipse

by | Dec 18, 2020 | Java

Introduction

Code Generation is the technique of generating source code of programs from the class diagram. This technique has been in use for several years now. It is often used to device obvious pieces of a program thereby relieving developers from writing long stretches of repetitive lines of code. In the Eclipse IDE, you have the facility of using code generation but through Papyrus SW designer, a component of Papyrus. To use this resource, you will have to download the latest version of Papyrus and plug it into your Eclipse directory or workspace. In this article we will discuss the steps for JAVA Code Generation in Eclipse.

Installation of Papyrus SW Designer

For all Java-related features, you have to navigate to the Papyrus Software Designer. Search for the SW Designer and download it on your desktop. During the Install, it will ask for the files you want to install. Select the ‘Papyrus Java profile, library, and code generation (Incubation)’ from the long list of files.

Code Generation from UML (Unifying Modelling Language) Elements

If you have a working UML model, you can successfully generate JAVA code for a package or a specific classifier by going through the simple steps listed below:

  • Open the page where you have the UML model or the model explorer and right-click on a particular package or specific classifier.
  • Click on Designer > Generate Java Code
  • You will thereafter see several JST dialogs. Follow the instructions and create a new JDT project in Eclipse. This is where the Java code will be generated (if no other JDT project is affiliated to your project).

A thing to be noted here is when you generate code for a classifier, some of the required classifiers are also generated along with the code. On the other hand, when you are generating code from a particular package, all of the classifiers and required classifiers of the package will be generated along with the code!

Author

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.