mercredi 2 juin 2010

JBoss specific packaging

I post this article in order to help several people who can be found one day in my case, package a war with Maven for JBoss.

The problem is to keep the possibility to package the war with the default configuration, in order to not integrate the JBoss specific files to other servers such as Tomcat.

I begin to isolated my webapp classloader so that JBoss only load the jars located into my war /lib
To begin I define a "jboss-classloading.xml" into a specific directory of my project, deditacted to JBoss files:


After that I define the classloader isolation of my webapp into the jboss-classloading.xml:
Because In Petals View, Spring is used, JBoss et Spring logger get in conflict so that I decided to create a second web.xml (located into src/main/jboss/web.xml) with the Spring logger listener commented, like this:
But the web.xml under src/main/webapp/WEB-INF/web.xml don't comment this listener, because it work correctly with others servers.

Now I have all specific files for the deployment work correclty under JBoss AS, I just have to create in my pom.xml a specific profile for JBoss.

Explanation: the specific JBoss profile like "jboss-packaging" will package the war with the specific JBoss files under /src/main/jboss (jboss-classloading.xml and web.xml)

This profile allow with the following maven command: mvn -P jboss-packaging to generate a specific war for JBoss deployment, and allow to keep the default war packaging for other servers with mvn package command. The default war packaging don't include the jboss-classloading.xml under /WEB-INF/ and use the web.xml located into /src/main/webapp/WEB-INF/web.xml of my project, instead the src/main/jboss/web.xml file.

The JBoss specific declaration profile, into pom.xml:

Now I have the possibility to package two differents war, in the first hand a specific war for JBoss deployment with mvn -P jboss-packaging command, and in the other and a default war packaging for other server deployments thank to mvn package command.


Thank for reading.

best regards,

Adrien