Skip to main content

Using Maven JAXB2 plugin to compile DTD

Posted by kohsuke on January 30, 2007 at 9:44 AM PST

Glassfish v3 is going to be based on Maven2, and I've been helping them to get it right. One of the work is to invoke JAXB's schema compiler to compile a DTD with XJC plugins. Once you know what to do, this is easy thanks to the excellent maven-jaxb2-plugin.

As with everything else in Maven, the hard part is to know how to do it. I thought this example might be useful for other folks, so decided to post it here. The crucial portion is the plugin configuration in :

<plugin><br />  <groupId>org.jvnet.jaxb2.maven2</groupId><br />  <artifactId>maven-jaxb2-plugin</artifactId><br />  <executions><br />    <execution><br />      <goals><br />        <goal>generate</goal><br />      </goals><br />      <configuration><br />        <cs_comment   if you want to put DTD somewhere else<br />        <schemaDirectory>src/main/jaxb</schemaDirectory><br />        --><br />        <extension>true</extension><br />        <schemaLanguage>DTD</schemaLanguage><br />        <schemaIncludes><br />          <schemaInclude>*.dtd</schemaInclude><br />        </schemaIncludes><br />        <bindingIncludes><br />          <bindingInclude>*.jaxb</bindingInclude><br />        </bindingIncludes><br />        <args><br />          <arg>-Xinject-listener-code</arg><br />        </args><br />      </configuration><br />    </execution><br />  </executions><br />  <dependencies><br />    <dependency><br />      <groupId>org.jvnet.jaxb2-commons</groupId><br />      <artifactId>property-listener-injector</artifactId><br />      <version>1.0</version><br />    </dependency><br />  </dependencies><br /></plugin><br />

The dependencies section inside the plugin element can be used to specify additional XJC plugins. If you'd like to use more recent version of the JAXB RI, you can specify a dependency to XJC here to do so, like this:

<dependency><br />  <groupId>com.sun.xml.bind</groupId><br />  <artifactId>jaxb-xjc</artifactId><br />  <version>2.1.2</version><br /></dependency><br />

The complete sample project is also available.

Related Topics >>