I suggest you to use Maven plugin maven-jaxb2-plugin
to generate classes from a .xsd
file. Use a binding file e.g. .xjb
to add annotations @XmlRootElement
. Example:
Binding file:
<bindings version="2.0" xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:annox="http://annox.dev.java.net">
<globalBindings>
<xjc:serializable uid="12343" />
<xjc:simple/>
</globalBindings>
</bindings>
POM (Maven plugin config):
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<args>
<arg>-Xannotate</arg>
<arg>-nv</arg>
</args>
<extension>true</extension>
<forceRegenerate>true</forceRegenerate>
<bindingDirectory>${basedir}/src/main/resources/schema/xjb</bindingDirectory>
<bindingIncludes>
<include>*.xjb</include>
</bindingIncludes>
<schemas>
<schema>
<fileset>
<directory>${basedir}/src/main/resources/schema/</directory>
<includes>
<include>*.xsd</include>
</includes>
</fileset>
</schema>
</schemas>
<debug>true</debug>
<verbose>true</verbose>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.2</version>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>0.6.2</version>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-namespace-prefix</artifactId>
<version>1.1</version>
</plugin>
</plugins>
</configuration>
</plugin>
See Maven JAXB2 Plugin User Guide