Integration with the Eclipse build mechanism
It is time to see our generator in action: launch Eclipse, create a Java Project in the workspace, and in the src
folder, create a new .entities
file (remember to accept to convert the project to an Xtext project, otherwise the generator will not run). Continue by adding one or more entities with some attributes. Note that a src-gen
folder is automatically created as soon as you save the file. At this point, you should also add this generated folder to the projects source folders by navigating to Build Path | Use as Source Folder. Exploring the content of the src-gen
folder, you will find a generated Java class for each entity in your .entities
file. You can see an example in the following screenshot:
Note
Observe that a code generator just creates text. Other components have to make sense of that, for example, a Java compiler. That is why we need to add the src-gen
folder to the project source folders: this way, the Eclipse Java compiler automatically...