Using the Maven 2 plugin for the Castor XML Code Generator Maven 2 plugin for the Castor XML code generator Configuration Integration into build life-cycle Example
Maven 2 plugin for the Castor XML code generator
For those of you working with Maven 2 instead of Ant, the Maven 2 plugin for Castor
can be used to integrate source code generation from XML schemas with the Castor XML
code generator as part of the standard Maven build life-cycle. The following sections
show how to configure the Maven 2 Castor plugin and hwo to instruct Maven 2
to generate sources from your XML schemas.
Configuration
To be able to start source code generation from XML schema from within Maven,
you will have to configure the Maven 2 Castor plugin as follows:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>castor-maven-plugin</artifactId>
<version>1.0</version>
</plugin>
|
|
Above configuration will trigger source generation using the default
values as explained at the
Castor plugin page,
assuming that the XML schema(s) are located at src/main/castor, and code will
be saved at target/generated-sources/castor. When generating sources
for multiple schemas at the same time, you can put namespace to
package mappings into src/main/castor/castorbuilder.properties.
To e.g. change some of these default locations, please add a
<configuration> section to the plugin configuration as
follows:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>castor-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<schema>src/main/resources/org/exolab/castor/builder/binding/binding.xsd</schema>
<packaging>org.exolab.castor.builder.binding</packaging>
<properties>src/main/resources/org/exolab/castor/builder/binding.generation.properties</properties>
</configuration>
</plugin>
|
|
Details on the available configuration properties can be found
here.
By default, the Maven Castor plugin has been built and tested against
a particular version of Castor. To switch to a newer version of Castor (not the
plugin itself), please use a <dependencies> section as shown below
to point the plugin to e.g. a newer version of Castor:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>castor-maven-plugin</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>org.codehaus.castor</groupId>
<artifactId>castor</artifactId>
<version>1.1-M3-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
|
|
Integration into build life-cycle%
To integrate source code generation from XML schema into your standard
build life-cycle, you will have to add an <executions> section
to your standard plugin configuration as follows:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>castor-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
|
|
Example
Below command shows how to instruct Maven (manually) to generate Java sources
from the XML schemas as configured above.
|