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:
- If you use Nexus or Artifactory, add the JBoss repository as a proxied repository.
- Define the repository in your
settings.xmlfile or the projectspom.xmlitself 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>
OK … that’s cool and all, but I would still have to open up the jboss-as-parent pom, find the module that looks like it may reference my artifact (in this case, jboss-as-hibernate-in), open up its pom file, in order to confirm just exactly how to specify the groupId and artifactId as used by the container.
I’d still like to find a good strategy to avoid all that cross referencing.
Oops … I take that back. I was looking at 6.0.0.Final pom when I said that. 7.0.0.Final seems to have the artifacts directly stated in its pom.
hi Steve
can you explain us with more details how do you achieve this?
Great tip!
Thank you for sharing this tip!
Perfect! thats what I’m looking for. Thanks