I have an akka application which I wish to package as an uberjar. If I package my application, the logback.xml appears in the root of the jar, but when I start my application I get an error in the configuration log because "URL x is not of type file!" where x is a url which looks like
jar:file:/path/to/jar!logback.xml
(Error appears here https://github.com/qos-ch/logback/blob/master/logback-core/src/main/java/ch/qos/logback/core/joran/spi/ConfigurationWatchList.java#L90)
This is because the logback file is archived, and so cannot be accessed as a file, which is what logback is expecting. I'm fine with this because the logback config shouldn't feature in a jar because it can result in conflicts. What I want to do is package and run my application, passing in the logback.xml at runtime, e.g
java -Dlogback.configurationFile=/full/path/to/logback.xml -jar myapplication.jar
When run like this, the logging configuration falls back to the default and I end up with actor logs appearing in my console (It all works as expected when running through maven). Tell me what I'm missing :)
Yes, it's not a good idea to package the logback.xml
file into your fat jar. The intention it to have it be configured at runtime. If you are using sbt
for assembling the jar, you can specify directories & files to not include by adding to unmanagedJars
. For example:
unmanagedJars in Compile <++= baseDirectory map { dir =>
(dir ** "logback.xml").classpath
}
Then you should be able to pass it in at runtime by including it after -cp
(classpath) or -jar
. For example:
java -jar -Dlogback.configurationFile=/full/path/to/logback.xml myapplication.jar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With