Creating a new Xtext project by default creates src and src-gen folders. However, sometimes one may wish for a more maven-like structure using src/main/java and src/generated/java. I want to briefly describe how to refactor an existing Xtext project (such that regenerating from the grammar file still works afterwards). Using these steps it should easily be possible to adapt new Xtext projects before the first generation of the Xtext artifacts, as well.
There are two main steps involved:
1) replacing the source folders src and src-gen by src/main/java and src/generated/java
2) making these changes known to the workflow file, so that these folders are used instead
Apply steps a)-c) to all three Xtext projects (they are essential only for the grammar and the ui one, though).
<classpathentry kind="src" path="src"/> and
<classpathentry kind="src" path="src-gen"/> from the .classpath files. And while you are at it, change the output entry from “bin” to “target/classes”.
b) Use the “New Src Folder”-Wizard to create src/main/java and src/generated/java. This adds them automatically to the .classpath file. But you still have to adapt the source..-entry in the build.properties. Use the quick fix (in the textual representation of the file) to add the new folders and remove src and src-gen manually.
c) Move the previous contents of src to the source folder src/main/java (don’t move the subfolders main or generated). Move the previous contents of src-gen to src/generated/java.
d) In the workflow file, point the directory cleaner components the the new folders, replacing src-gen by src/generated/java.
e) Also add the following properties to the Generator component in order to let it know the new folders:
<srcPath value="/src/main/java"/> and
Xtext sample project after maven structure refactoring
f) You may want to delete the src-gen- and the bin-folders in all the projects. The generator project may call for a different folder structure. Feel free to choose your own. I also recommend to use package names more unique than templates, model and workflow, in particular if you have several Xtext projects in the same environment. Don’t forget to modify the generator-project’s workflow file (targetDir, template path etc.), template and extension file(s) accordingly.
P.S.: Of course it would be nice if the New Xtext Project wizard had a tick box “use Maven folder structure”