This question already has an answer here:
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
Properties file doesn' go in classpath, you must provide it and call it from code as shown here.
EDIT: With your directory structure you call it like this:
EDIT2:
Also, you must provide appender for it:
If you want finer control over logging, remove the first line (root looger) and put the second one where instead of [logger-name] you put the topmost package so that all the classes inside that package can use logging.
You can define multiple appenders and assign them to different classes in that manner.
You can also start your JVM with argument:
to specify arbitrary location of your external log properties. I used this a lot in one particular project.
PropertyConfigurator.configure(ABC.class.getResourceAsStream("log4j.properties"))
worked me correctly, but basically you need to place Log4j properties file in Source Code folder (next to Java Class).OR you can try putting outside and give proper path in
getResourceAsStream("resources/log4j.properties")
method