Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load log4j.properties with JAR [duplicate]

Tags:

java

jar

log4j

I have a jar file with the following Manifest

Manifest-Version: 1.0  
Created-By: 1.7.0_07 (Oracle Corporation)  
Main-Class: test.Main  
Class-Path: ./log4j.properties lib/log4j-1.2.17.jar 

I run the class as follows

java -jar test.jar

And this is my folder

lib
log4j.properties
test.jar

Why I can't see the log4j properties file? This is what I see

log4j:WARN No appenders could be found for logger (test.Main).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

Thank you

SOLUTION: changed my classhpath in the MANIFEST to this

Class-Path: . lib/log4j-1.2.17.jar 
like image 986
mottalrd Avatar asked Oct 05 '12 13:10

mottalrd


1 Answers

You can also start your JVM with argument:

-Dlog4j.configuration=file:"./your/properties/path/log4j.properties"

to specify arbitrary location of your external log properties. I used this a lot in one particular project.

like image 63
Less Avatar answered Oct 19 '22 08:10

Less