1. Introduction.
This plugin uses JAXB2 to generate Java classes from XML Schemas (and binding files) and to create XML Schemas for existing Java classes.
General Information about the plugin goals:
- jaxb2:schemagen Creates XML Schema Definition (XSD) file(s) from annotated Java sources.
- jaxb2:testSchemagen Creates XML Schema Definition (XSD) file(s) from annotated Java test sources.
- jaxb2:xjc Generates Java sources from XML Schema(s).
- jaxb2:testXjc Generates Java test sources from XML Schema(s).
2. How to config it in pom.xml
The following example demonstrates a basic plugin configuration for generating Java sources from XML schemas:
<project> ... <dependencies> <dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> <version>2.1</version> </dependency> ... </dependencies> ... <build> <pluginManagement> <plugins> <!-- Need Java 5, which is the default since v2.3 of the maven-compiler-plugin. --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.5.1</version> </plugin> </plugins> </pluginManagement> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>jaxb2-maven-plugin</artifactId> <version>1.5</version> <executions> <execution> <id>xjc</id> <goals> <goal>xjc</goal> </goals> </execution> </executions> <configuration> <packageName>com.example.myschema</packageName> <!-- The name of your generated source package --> </configuration> </plugin> ... </plugins> <build> ... </project>In this example, the plugin will generate Java sources from all XML schema files in the default schema directory ( ${project.basedir}/src/main/xsd). The package of the generated sources will be 'com.example.myschema' as defined by the packageName configuration element.
Attention: the plugin requires at least the Java 5.0 compiler.
4. How to use the plugin in your project.
See http://docs.oracle.com/javase/6/docs/api/javax/xml/bind/JAXBContext.html
Other references:
http://mojo.codehaus.org/jaxb2-maven-plugin/index.htmlhttp://blog.csdn.net/xjtuse_mal/article/details/6930538