tags:

views:

80

answers:

3

I have an application that I've developed. Currently it is deployed with all its config files (including log4j.properties, as used by some external libs I use) in the same dir as my application.

So, I have a bin dir, containing my app.jar, plus a few properties files, plus a lib dir with all my external jars. The external jars are specified in a classpath specified in the app.jar's manifest file.

Now the powers that be have decreed that the new structure will be a bin dir with just the app.jar, with a lib dir at the same level (i.e. ../lib, relative to bin) for external jars and a ../etc directory for configuration files.

Easy enough, I thought -- I changed all the classpath paths from ./lib/<jarname> to ../lib/<jarname>, and added ../etc to the classpath as well.

Problem is that now any jars that use log4j don't work -- they don't see the log4j.properties file -- because, I suspect, the classpath for app.jar doesn't affect the classpath for the external jars (maybe?), and previously they were finding it simply because it was in '.'.

Any thoughts?

A: 

So, the issue is that Log4J now doesn't find the configuration file (log4j.properties) automatically anymore?

As far as I know, Log4J by default looks in the directories that are in the classpath for the log4j.properties file. Try adding the ../etc directory in the classpath in the manifest file of your JAR.

See also Default Initialization Procedure in the Log4J Manual, it explains how Log4J looks for the configuration file and how you can change this.

Jesper
A: 

log4j.properties has to be somewhere in the default package, which in your case probably means in a JAR file somewhere in the root directory of that jar file.

A better solution would be to stick it in the etc directory, and then explicitly configure log4j to use it from that location. You can do that using PropertyConfigurator - invoke that when your application starts up, by filename, URL, whatever suits you best.

skaffman
+1  A: 

You can put the log4j.properties anywhere as long as it is in the classpath. so, as @skaffman suggested, put the log4j properties file in the etc directory which is already in your classpath.

An alternative to using PropertyConfigurator is to set this syetm property while running your app.

-Dlog4j.configuration=log4j.properties
Rahul