What is the scope of System.setProperty()? If I set it in one of the classes in a Java EE application, would all the other classes and other components that use System.getProperty() or use other ways of accessing the property, be able to view the value that has been set?

For example, I am using:-

System.setProperty("catalina.home", "C:");

Later on other a number of xml files look for context in a property file in CLASSPATH which is catalina.home. However, these files cannot find the property file. So I am wondering if I am doing something wrong.

有帮助吗?

解决方案

It has application-wide scope, but it's in memory. More specifically, it's scoped to the runtime. However, once the application ends, it's gone, i.e. changes made to system properties are not persisted.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top