0

I have a Java application which I'm executing on Linux direct from an executable jar file

java -cp .:./lib -Duser.timezone=GMT -Dlog4j.debug -jar programName.jar

The program uses a number of other jar files which are all in one directory and 4 properties files all of which are in another directory (the current directory). Both directories are included in the CLASSPATH.

Simple enough right.

It would be, except that Log4j fails to find log4j.properties. The only way I have managed to make it find log4j.properties is to include it in programName.jar

This is not what I want, I want to have it using log4j.properties residing in the same directory as all the other properties files, they are in the CLASSPATH and are found as you would expect.

The other jar files being used are:

  • jdom-2.0.5.jar
  • log4j-1.2.17.jar
  • ojdbc7.jar
  • quartz-2.2.1.jar
  • slf4j-api-1.7.7.jar
  • slf4j-log4j12-1.7.7.jar

I'm wondering if slf4j-log4j12-1.7.7.jar does some configuration which prevents log4j from scanning the CLASSPATH when looking for the properties file. My code does not include any instructions which aim to specify the location of the properties file.

I've not yet tried executing the program without the -jar option, I will try that next.

Does this ring any bells so far ?

Paul Vargas
  • 41,222
  • 15
  • 102
  • 148
user835745
  • 1,974
  • 3
  • 17
  • 18

1 Answers1

1

Add an argument to jvm (log4j.configuration). e.g.:

java -cp .:./lib -Dlog4j.configuration=file:log4j.properties -Duser.timezone=GMT ...

You may want to see this answer for more options.

Community
  • 1
  • 1
Paul Vargas
  • 41,222
  • 15
  • 102
  • 148
  • Thank you for your suggestion but I do not understand your reasoning. My log4j.properties is custom only in the sense of what it contains. Its name and location are standard. Please could you elaborate explaining why I need to specify the name when I'm using the standard (non xml) name. – user835745 Sep 26 '14 at 15:55
  • Hello Paul, thank you, your suggestion did help, it got me going. Sadly I am left frustrated not knowing why Log4j is failing to find log4j.properties even though it's in the CLASSPATH. – user835745 Sep 29 '14 at 19:09