Home JBoss howto Configuration How to configure log4j in your ear ?
30 | 07 | 2010
JBoss 5 AS Book
"JBoss AS 5 development" reviews
Please share your feedback/review with other readers!
Banner
Dashboard
Advertise with Us
Banner
RSS Feed
Java EE 1.6 resources
Login
Sign here for the NewsLetter.



JBoss admin resources
Banner
Java EE 1.6 resources
JBoss howto

How to avoid the 50 seconds start up limit in Eclipse ?

JBoss recipe of the day ...
Read More

How can you solve deployment errors caused by large war/jar/ear files ?

jboss recipe of the day ...
Read More

How do you configure your .war to be deployed after your EJB ?

jboss recipe of the day ...
Read More
How to configure log4j in your ear ?
Written by Mark S.   
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 log4j.properties file and package it with your application and make it visible to JBoss classpath (see image at the bottom). The log4j.properties has just a minimal content: 

log4j.logger.com.sample=TRACE


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 log4j.properties 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:
<jboss-app>
 <loader-repository>
   org.myapp:loader=MyClassLoader
   <loader-repository-config>
      java2ParentDelegation=false
   </loader-repository-config>
 </loader-repository>
 
</jboss-app>

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

JBoss.org Search
Custom Search
Comments
Search
Only registered users can write comments!

3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."