Reputation: 3116
I'm trying to load logback.xml
file from outside of my executable myapp.jar
file.
The myapp.jar
has a META-INF/MANIFEST.MF
file roughly like this:
Manifest-Version: 1.0
Class-Path: logger-config lib/lib/jcl-over-slf4j-1.7.18.jar lib/slf4j-api-1.7.18.jar
Main-Class: com.mycompany.MyAppMain
and resides in
my-app/
lib/
jcl-over-slf4j-1.7.18.jar
slf4j-api-1.7.18.jar
logger-config/
logback.xml
myapp.jar
(there is a lot of other jar dependencies, cut those out).
Now, if I run the application using java -jar myapp.jar
, it starts OK, but it does not pick up the logback.xml file.
From their docs:
If no such file is found, it checks for the file logback.xml in the classpath..
( http://logback.qos.ch/manual/configuration.html )
I know I can override this using logback.configurationFile
, but is there a way to just put the XML file to classpath so that logback loads it automatically? It seems to work only if I package the logback.xml
to myapp.jar
(placing it in src/main/resources
dir), but then the config file will be propagated to other JARs that uses myapp.jar
as a dependency.
Upvotes: 0
Views: 1083
Reputation: 2566
Maybe you just cut it out, but your classpath does not specify the logback-classic
dependency.
You will have to make sure logback
appears before slf4j
in your class-path definition. Also, note the trailing slash for the logger-config
path - logback will not find your logback.xml
without it (see here for details).
Something like this should work:
Class-Path: lib/logback-classic-1.1.6.jar lib/logback-core-1.1.6.jar lib/jcl-over-slf4j-1.7.18.jar lib/slf4j-api-1.7.18.jar logger-config/
Upvotes: 1