I use the codehaus jaxb-maven-plugin to create java classes from xml schemas:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>xjc</id>
<phase>generate-sources</phase>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<sources>
<source>src/my.xsd</source>
</sources>
<packageName>mypackage</packageName>
</configuration>
</execution>
</executions>
</plugin>
The classes are generated as expected to target/generated-sources/jaxb
, but this path is not added to the classpath.
So, if I use some of generated classes in other (not generated) classes, maven cannot found it during the compile process.
Any ideas? TIA!
JAXB 2 Maven Plugin. Mojo's JAXB-2 Maven plugin is used to create an object graph from XSDs based on the JAXB 2.x implementation and to generate XSDs from JAXB annotated Java classes.
– Using build-helper-maven-plugin : Add the plugin in pom.xml as shown below. We just need to add the goal add-source and provide the generated code directory under sources to add as source in our project. Add above plugin in your pom.xml, re-execute mvn clean compile, and you should see something similar as shown below:
Create xsd directory in src/main/resources and copy yours XSD’s into this folder. In this case, we use org.xsd to create java objects By default, jaxb2-maven-plugin scans XSD schema directory src/main/xsd for XML schema files to create Java source code
If you want to create an executable jar file, you need to configure Maven Archiver accordingly. You need to tell it which main class to use. This is done with the configuration element. Here is a sample pom.xml configured to add the classpath and use the class fully.qualified.MainClass as the main class:
It is a bug in the jaxb2-maven-plugin:
https://github.com/mojohaus/jaxb2-maven-plugin/issues/44
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