February 22, 2009

New stuff for JBoss in the Maven EAR plugin

It's been a number of years ago that I contributed to some open source project. To be more accurate, it was some four years ago that I submitted some bug fixes and features to OpenSymphony's WebWork 2 (which is now known as Struts 2.0).

After all these years I once again modified an open source project to do something I needed, and this time it was Maven's EAR Plug-in.

On release of version 2.3.2, you will be able to do following:
  • Generate XML-files for JBoss 5.0
  • Specify an alternate 3rd-party library directory
  • Specify both the loader-repository and loader-repository-config sections
  • Set an alternative configParserClass and loaderRepositoryClass
As an example, you can now set following configuration for the EAR plugin:

<plugin>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
...
<jboss>
<version>5</version>
<library-directory>/APP-INF/lib</library-directory>
<loader-repository>org.mindbug:loader=${project.build.finalName}.ear</loader-repository>
<loader-repository-config>java2ParentDelegation=false</loader-repository-config>
</jboss>
</configuration>
</plugin>

... which would create a jboss-app.xml with the corresponding configuration.

Anyway, if you can't wait for the release of version 2.3.2, just fetch the source code and compile it.

Enjoy! :)

February 9, 2009

Adding endorsements to Maven's plugins

Since Java 1.6 a number of libraries come piggybacking with the JDK installation. These are namely JAXB and JAX-WS, amongst others. Great in a way, however, if you previously built your project with Maven on Java 1.5, you may get worrying runtime exceptions when executing the build artifacts.

If you, just like me, ran into these obvious class path problems you will have to tell Maven to endorse dependencies on compile (and possibly when executing your unit tests).

Out of the box Maven doesn't seem to support this (I am using the latest 2.0.9), so I started to experiment a little and the solution turned out to be relatively straight forward and easy to implement.

Provided you already have a POM-file, simply add a profile called jdk16-override (or anything you like) and use the maven-dependency-plugin to copy the endorsed files automatically to a folder called endorsed.

Once the plugin has done it's job, you can reconfigure the maven-compiler-plugin and the maven-surefire-plugin to actually use the endorsement directory.

The following snippet of XML serves as a working example for JBossWS, however, it will work for any other library you may need to endorse:

<profiles>
<profile>
<id>jdk16-override</id>
<activation>
<jdk>1.6</jdk>
</activation>
<build>
<plugins>
<plugin>
<artifactid>maven-dependency-plugin</artifactid>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactitems>
<artifactitem>
<groupid>jboss</groupid>
<artifactid>jboss-jaxws</artifactid>
<version>4.3.0.GA</version>
<outputdirectory>${project.build.directory}/endorsed</outputdirectory>
</artifactitem>
<artifactitem>
<groupid>jboss</groupid>
<artifactid>jboss-jaxrpc</artifactid>
<version>4.3.0.GA</version>
<outputdirectory>${project.build.directory}/endorsed</outputdirectory>
</artifactitem>
<artifactitem>
<groupid>jboss</groupid>
<artifactid>jboss-saaj</artifactid>
<version>4.3.0.GA</version>
<outputdirectory>${project.build.directory}/endorsed</outputdirectory>
</artifactitem>
</artifactitems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactid>maven-compiler-plugin</artifactid>
<configuration>
<compilerargument>-Djava.endorsed.dirs="${project.build.directory}/endorsed"</compilerargument>
</configuration>
</plugin>
<plugin>
<artifactid>maven-surefire-plugin</artifactid>
<configuration>
<argline>-Djava.endorsed.dirs="${project.build.directory}/endorsed"</argline>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

You may have noticed the profile's activation policy. It simply tells Maven that this profile should be activated automatically if the build is performed on version 1.6 of the JDK.

Finally, I should mention that the JBossWS dependencies provided in the example aren't in Red Hat's repository. They refer to artifacts which I have in my local repository as they belong to the enterprise version of JBoss.

And as usual: Good luck and enjoy!