How to configure log4j in your ear ?

User Rating: 5 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Active

JBoss recipe of the day

Have you got exceptions when tried to configure log4j at application level ? this is due to the fact that JBoss ships already with log4j classes:  you need to isolate the classes from other deployments. Without isolation, you can see common errors like ClassCastException, IllegalAccessErrors, VerifyErrors and in general, strange behavior.
Here's how to do it:
Create a file and package it with your application and make it visible to JBoss classpath (see image at the bottom). The has just a minimal content:



Within your application you need to add the appropriate version of log4j jar (this is important  because you will have to ensure that log4j initializes separately for your application and picks up the file). Place this log4j jar file in the lib folder of your EAR (as depicted in the picture).

Finally you need to  enable classloader isolation for your application. In order to achieve classloader isolation you need to add an entry in jboss-app.xml file and place it in the META-INF folder of the EAR. The jboss-app.xml looks like:

     <loader-repository-config>java2ParentDelegation=false </loader-repository-config>

This is how your application EAR should look like:
jboss log4j

Follow us on Twitter