In the following example System.setProperty
used
public class LoadLogPropertiesFile {
static {
// must set before the Logger
String path = LoadLogPropertiesFile.class.getClassLoader().getResource("logging.properties").getFile();
System.setProperty("java.util.logging.config.file", path);
}
private static Logger logger = Logger.getLogger(LoadLogPropertiesFile.class.getName());
public static void main(String[] args) {
...
As you might guess this will set the system property with the key java.util.logging.config.file
, right?
From the docs
This may result in a SecurityException being thrown. If no exception is thrown, the specified property is set to the given value.
As a result no exception was thrown and no system property with a given name was detected after this code finished. What is wrong?
Values that you set with System.setProperty()
are stored in a Properties
object of the currently running JVM. You can retrieve that Properties
object through System.getProperties()
or access values from that Properties
object with System.getProperty()
.
These properties are not made visible to any process outside of the currently running JVM.