My dilemma is that I have my doubts regarding generated source files in maven.
I'm trying to generate some classes from a WSDL and I don't really know what is the standard way to handle the resulting source files.
What are the best-practices regarding this issue? Any help or advice is appreciated.
Thanks for your kind answers, Mark
Most of the Maven plugins I've come across that generate code follow a convention of placing the generated Java source files in a sub-directory of the target/generated-sources
folder. For an example, the Maven 2 JAXB 2.x Plugin generates the Java sources in the target/generated-sources/xjc
folder.
As long as the build is repeatable I don't see the need to commit the generated sources to my source code repository. So I usually configure my Git, Mercurial, SVN or whatever I am using to ignore everything under target
.
I usually manually edit the .classpath
file to include the source folder for Eclipse and I store both the .classpath
and .project
files in the source code repository.
Here is an example:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" path="target/generated-sources/xjc"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
It is important to note that some Maven plugins don't attach the generated sources to the POM. You can use the Build Helper Maven Plugin to over come this.
I never found a standard way to handle the resulting source files. However, based on my experience I would recommend you the following:
- Where should I generate the .java source files? (src/main/java, src/main/generated)
- Should I include them under source control, or let them be generated after check-out
- If I don't use the src/main/java folder, how to convince Eclipse automatically to "see" those classes as source folder?
- Do I really need the .java files, or only the .class-es?
Just my two cents, after years of using JAXB, mainly for WSDL to Java generation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With