Before you begin it may be necessary to familiarize yourself with the XMLBeans. A good tutorial can be found here.
Basic usage consists of adding a reference to the plugins section of your Maven 2 project as shown here.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xmlbeans-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>xmlbeans</goal>
</goals>
</execution>
</executions>
<inherited>true</inherited>
<configuration>
<schemaDirectory>src/main/xsd</schemaDirectory>
</configuration>
</plugin>The goals available are are xmlbeans:xmlbeans and xmlbeans:xmlbeans-test.
By default, the plugin looks for the src/main/xsd directory to exist, so it isn't necessary to specify it. Nor do you need to specify src/main/xsdconfig, the assumed location of any xsd config files to use during the parsing and creation of the object model. However, you can add additional xsdconfig directories as shown below.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xmlbeans-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>xmlbeans</goal>
</goals>
</execution>
</executions>
<inherited>true</inherited>
<configuration>
<xmlConfigs>
<xmlConfig implementation="java.io.File">src/main/xsdconfig</xmlConfig>
<xmlConfig implementation="java.io.File">
src/main/xsdconfig2/explicit.xsdconfig
</xmlConfig>
</xmlConfigs>
</configuration>
</plugin>XML Beans models may be generated for the test compile as well. Although the schemaDirectory is defined in the example below, the default xsd directory for the test cycle is in fact src/test/xsd.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>maven-xmlbeans-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>xmlbeans-test</goal>
</goals>
</execution>
</executions>
<inherited>true</inherited>
<configuration>
<schemaDirectory>src/test/xsd</schemaDirectory>
</configuration>
</plugin>Schemas located within an artifact jar your project is dependent upon can be used as source schemas. In the example below the geronimo-tomcat jar is expected to be a listed depedency of the project. Any schemas ending with .xsd or .XSD will be extracted from the artifact and an object model of these schemas will be produced. Also in the example, the memory max of the schema compiler is set - this may be needed for large schema sets.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xmlbeans-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>xmlbeans</goal>
</goals>
</execution>
</executions>
<configuration>
<memoryInitialSize>50m</memoryInitialSize>
<memoryMaximumSize>80m</memoryMaximumSize>
<xsdJars>
<xsdJar implementation="java.lang.String">geronimo:geronimo-tomcat</xsdJar>
</xsdJars>
</configuration>
</plugin>In some cases it's necessary to customize where the generated sources produced by the plugin are stored. This can be done by explicitly defining the source generation directory. The default is target/generated-sources/xmlbeans.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xmlbeans-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>xmlbeans</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceGenerationDirectory>
target/generated/xmlbeans
</sourceGenerationDirectory>
</configuration>
</plugin>