Tags

, ,

The Problem

In the past I’ve always been annoyed with trying to keep the version of dependencies within projects in sync with the versions that are provided as part of the JBoss distribution. This has always been done through a manual process whereby I inspect the jar-versions.xml to find the version of the relevant artefact and then adding that version information into the projects POM file. This becomes even more tedious when we need to migrate the project to a newer version of JBoss, at which point we need to go through this process again.

I’m sure there must have been a better way to get around this, but unfortunately I’ve never come across an easy way of doing this it’s always coming down to doing what’s described above in one way or another.

The Solution

The way I’ve managed to resolve this with JBoss 7 is by importing the jboss-as-parent POM file available through the JBoss Nexus Repository in the depencyManagement section using the import scope, which then imports all the versioning information for artefacts used within the application server.

The import scope allows you to import the managed dependencies from one POM into another, making it seem as if the those dependencies were specified in the dependencyManagement section of the current POM itself. More information about the import scope can be found here.

After this you can start using the required artefacts within the project without having to specify versioning information, and Maven will resolve those dependencies to the version specified in the jboss-as-parent POM.

Step by Step Guide

Add JBoss Repository Information

The first step is to add the JBoss repository information Maven. This can be done by using one of the following methods:

  1. If you use Nexus or Artifactory, add the JBoss repository as a proxied repository.
  2. Define the repository in your settings.xml file or the projects pom.xml itself by following the instructions specified here.

Import jboss-as-parent

This is done by adding the following in the dependencyManagement section in the project’s (parent) POM:

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.jboss.as</groupId>
      <artifactId>jboss-as-parent</artifactId>
      <version>7.0.0.Final</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

Add the required dependencies

And the final step is to add the required dependencies in the dependencies section of your POM. Note that you don’t need to specify the version tag, and that I’ve specified the scope of the dependency as provided as it’ll be available through the container.

<dependencies>
  <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <scope>provided</scope>
  </dependency>
</dependencies>
About these ads