How to configure logging when running a JAR?

jar, java, logging

Solution

You can't specify JVM arguments into the MANIFEST.MF file so you have to specify the logging properties at the command line or with a shortcut :

java -Djava.util.logging.config.file=logging.properties -jar yourjar.jar

Otherwise you could package a properties file(logging.properties in your case) in the JAR, read that at startup and put those settings into the system properties.

Problem

I am new to Java logging API and need some help with this problem: While creating the application, my config file was stored in the project root folder, so I used `-Djava.util.logging.config.file=logging.properties` switch to run the program. But then I exported the executable JAR. How to configure the logging now? It doesn't work, when I specify the path to config file with the -D switch.

Original source