A software’s log4j framework could not find the log4j configuration file which I specified. Details with debug below:



java -Dlog4j.debug=true -Dlog4j.configuration=/mysoftware/config/ ...


Debug Output:

log4j: Trying to find [mysoftware/config/] using context classloader sun.misc.Launcher$AppClassLoader@164b95.
log4j: Trying to find [mysoftware/config/] using sun.misc.Launcher$AppClassLoader@164b95 class loader.
log4j: Trying to find [mysoftware/config/] using ClassLoader.getSystemResource().
log4j: Could not find resource: [mysoftware/config/].



I did not want to use the default location for the log4j configuration file and wanted to be able to specify to a file with a name and location of my choice.



The debug output indicates that the absolute path of the resource ( is missing a beginning “/”. That’s because the file:// protocol was not specified. So, the following worked and enabled log4j locate the properties file:


java -Dlog4j.debug=true -Dlog4j.configuration=file:///mysoftware/config/ ...

NOTE: If your log4j configuration file is called log4j.xml or, then placing it in the application classpath will suffice and you will not need the -Dlog4j.configuration option.



Root Cause:

The file:// protocol was not used to specify the log4j configuration file.



Short Introduction to log4j – Ceki Gülcü



(1) The solution above describes a successful problem-solving experience and may not be applicable to all problems with similar symptoms.

(2) Your rating of this post will be much appreciated. Also, feel free to leave comments.

VN:F [1.9.22_1171]
Rating: +15 (from 17 votes)