In my previous blog (
http://magnus-k-karlsson.blogspot.se/2012/04/handling-java-enterprise-dependency.html) I was talking about the hardship of using Maven when developing Java Enterprise Applications. And this following up blog I will show the best practice I think of handling JBoss Enterprise dependency with Maven.
First when using JBoss dependency you will have to add the JBoss Repository. You can add this in your personal Maven configuration file, settings.xml as described at the JBoss Community page
https://community.jboss.org/wiki/MavenGettingStarted-Users. Or you can add the repository in your parent pom. I think the best way is to do it in your parent pom, since it is more clear to less experience programmers.
<repositories>
<repository>
<id>jboss-public-repository-group</id>
<name>JBoss Public Maven Repository Group</name>
<url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
</repository>
</repositories>
<pluginrepositories>
<pluginrepository>
<id>jboss-public-repository-group</id>
<name>JBoss Public Maven Repository Group</name>
<url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
</pluginRepository>
</pluginRepositories>
I have left out the rest of the configuration, since it is anyway default values, you can read more about the above configuration below:
Maven 2.2.1
http://maven.apache.org/ref/2.2.1/maven-settings/settings.html
Or if you already have upgraded to the latest Maven 3 version:
http://maven.apache.org/ref/3.0.4/maven-settings/settings.html
If you are using a different version of maven simple change the above URL with you maven version.
Now to the real work adding JBoss Enterprise Dependency. The hardest part is the first part. What is the groupId and artifactIf for the JBoss dependency? And this is not at all clear at the beginning. But Red Hat have submitted a version fil with JBoss:
JBoss AS (Community Edition) and JBoss EAP (Enterpise Application Platform)
$JBOSS_HOME/jar-versions.xml
When looking for Maven Dependency groupId and artifactId you should look for
implVendorID which is groupId and
implVersion which is the version in Maven. But the problem is in most cases implVendorID is replaced with an URL, that will not help us much.
But JBoss have actually deployed there dependency matrix in there repository:
https://repository.jboss.org/nexus/content/groups/public-jboss/org/jboss/jbossas/jboss-as-component-matrix/
As you can see they have preserved the groupId and artifactId for most of there JBoss releases and that is a good, because that makes component more easy to discover. But instead of now searching the component matrix for the specific dependency and it version you can actually import this pom to maven with
<?xml version="1.0" encoding="UTF-8" ?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
...
<properties>
<jbossas.version>5.1.0.GA</jbossas.version>
</properties>
<dependencymanagement>
<dependencies>
<dependency>
<groupid>org.jboss.jbossas</groupId>
<artifactid>jboss-as-component-matrix</artifactId>
<version>${jbossas.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
And now to import the JBoss Enterprise Dependency:
<dependency>
<groupid>org.jboss.javaee</groupid>
<artifactid>jboss-javaee</artifactid>
<scope>provided</scope>
</dependency>
NOTE: that here I'm not specifying the version number that is retrieved from the above pom import. You can verify that either with m2eclipse or with Maven:
$ mvn dependency:tree
Sadly the JBoss Enterprise Dependency jboss-javaee is not always complete, so if you are for example using standard JAX-WS you will have to add that additionally:
<dependency>
<groupid>org.jboss.ws.native</groupid>
<artifactid>jbossws-native-jaxws</artifactid>
<scope>provided</scope>
</dependency>
And if you are programming MBeans they are not at all defined in the jboss-as-component-matrix, so you will have to completely add them with version:
<dependency>
<groupid>org.jboss.jbossas</groupid>
<artifactid>jboss-as-system-jmx</artifactid>
<version>${jbossas.version}</version>
<scope>provided</scope>
</dependency>
Well nothing is perfect but with this way the dependency should be a little more clearer and easier to maintain.