Java – log4j configuration in EAR

earjavalog4j

I have an EAR composed of ejb.jar archives.

Where can / should I place my log4j.xml configuration file in my EAR in order to configure log4j for the different EJBs?

Here is my following structure:

myEar
|-- myEjb1.jar
|-- myEjb2.jar
|-- myEjb3.jar
|-- lib
    | -- myLib1.jar
    | -- myLib2.jar

Thanks in advance!

Best Answer

If log4j is used by different modules in the ear, it should be placed in a jar which is placed in the lib directory of the ear. But it is not very convenient since you will have to re-assemble your ear and redeploy it each time you change a log level.

Another option is to place the log4j config file in the folder and add that folder in the classpath of the ear. Most app server provides this feature (WebSphere for instance). It is less portable but more manageable: the config can be changed without redeploying the ear.

Related Topic