Wednesday, March 26, 2008

JAXB with Maven

Finally Sun has Maven repositories for getting Sun jars and also they have a nice plugin for generating JAXB 2 classes with Maven using the maven-jaxb2 plugin. It defaults to generating schemas located in src/main/resources and the generated output goes to target/generated-sources/xjc. The generated output will automatically be included in your final jar.

Excerpt from pom.xml

<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.1</version>
<scope>test</scope>
</dependency>


<build>
<plugins>
<plugin>
<groupid>org.jvnet.jaxb2.maven2</groupid>
<artifactid>maven-jaxb2-plugin</artifactid>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>


<repositories>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net Maven 2 Repository</name>
<url>http://download.java.net/maven/2</url>
</repository>
</repositories>

<!-- For maven-jaxb2-plugin -->
<pluginrepositories>
<pluginrepository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net Maven 2 Repository</name>
<url>http://download.java.net/maven/2</url>
</pluginrepository>
</pluginrepositories>

No comments: