Java: log4j: problem with executable jar

My log4j works fine when I run "java pakcage.Main" from the command line, but when I run the same program with an executable jar like "java -jar myjar.jar", I get the following err:

log4j:WARN No appenders could be found for logger log4j:WARN Please initialize the log4j system properly 

log4j.jar and log4j.properties are in my Class-Path manifest.

I am sure that it worked correctly once, but after rebuilding it does not work.

+4
source share
3 answers

You can list only jar files or directories as part of the class path. Instead of specifying log4j.properties you should specify the directory in which the properties file is located relative to the executable jar.

Example:

If myjar.jar is in the base directory, log4j.jar in. / Lib / and log4j.properties in. / conf /

The path class entry in myjar.jar as follows

Path class: lib / log4j.jar conf /

+4
source

I believe that you can also just add the log4j.xml file (or log4j.properties) inside your custom Jar file. As long as it is at the root of your Jar file, the log4j structure will be able to find it.

+1
source

Source: https://habr.com/ru/post/1369290/


All Articles