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>

Friday, March 7, 2008

Spring by Example Site is Open!

The Spring by Example site is finally open! I've been working this for a couple of months, but wanted it to be fairly nice when it went live. It has a few good examples and I have more to post. A few people I know have said they will contribute examples as they have time also. These are some of my favorite examples posted so far.


Tim Voet also posted an example using a BeanPostProcessor to dynamically insert a logger based on the bean's class if it has a setLogger method. This is a nice way to avoid typos when creating loggers.