|  |  |  | License Codehaus OpenEJB OpenJMS OpenORB Tyrex

Old releases
General
Release 1.3
Release 1.3rc1
Release 1.2

Main
Home
About
Features
Download
Dependencies
Reference guide
Publications
JavaDoc
Maven 2 support
Maven 2 archetypes
DTD & Schemas
Recent HTML changes
News Archive
RSS news feed
Project Wiki

Development/Support
Mailing Lists
SVN/JIRA
Contributing
Support
Continuous builds
Prof. services

Related projects
Spring ORM support
Spring XML factories
WS frameworks

XML
XML

XML Code Generator
XML Code Generator

JDO
Introduction
First steps
Using JDO
JDO Config
Types
JDO Mapping
JDO FAQ
JDO Examples
JDO HOW-TOs
Tips & Tricks
Other Features
JDO sample JAR

Tools
Schema generator

Advanced JDO
Caching
OQL
Trans. & Locks
Design
KeyGen
Long Trans.
Nested Attrs.
Pooling Examples
LOBs
Best practice

DDL Generator
Using DDL Generator
Properties
Ant task
Type Mapping

More
The Examples
3rd Party Tools
JDO Tests
XML Tests
Configuration

About
License
User stories
Contributors
Marketplace
Status, Todo
Changelog
Library
Contact
Project Name

## 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.

    > mvn castor:generate

<notice> Copyright © 1999-2005 ExoLab Group, Intalio Inc., and Contributors. All rights reserved. </notice>
<notice> Java, EJB, JDBC, JNDI, JTA, Sun, Sun Microsystems are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and in other countries. XML, XML Schema, XSLT and related standards are trademarks or registered trademarks of MIT, INRIA, Keio or others, and a product of the World Wide Web Consortium. All other product names mentioned herein are trademarks of their respective owners. </notice>