I've been working on a set of software that loads its configuration from a
properties-style config file specified as the command-line argument. The
configuration-loader reads the properties (mainly relative paths to data
files) from the config file and stores them with System.setProperty(String,
String), so that all classes can read them easily with getProperty(String).
In effect, I've been using the system properties as a global warehouse of
String variables, to avoid having to pass additional references to every
class that might need these variables.
We're now developing a web application version of the software, and I've
discovered that the system properties are not writable [1] from an
application running in Tomcat5, so I can't store the configuration data
this way.
Is it possible to override this -- at least in a limited way?
If so, how dangerous is it?
Or what alternatives do you suggest for making the configuration information
globally accessible?
Thanks,
Adam
[1] Here's the exception:
java.security.AccessControlException: access denied
(java.util.PropertyPermission cafetiere.tbl1.trainer.corpus write)
at
java.security.AccessControlContext.checkPermission(AccessControlContext.java:269)
at
java.security.AccessController.checkPermission(AccessController.java:401)
at
java.lang.SecurityManager.checkPermission(SecurityManager.java:524)
at java.lang.System.setProperty(System.java:654)
at
uk.ac.nactem.util.CafetiereConfig.loadConfiguration(CafetiereConfig.java:102)
Line 102 is:
System.setProperty(key, value);
Steve W. Jackson - 14 Nov 2005 17:25 GMT
> I've been working on a set of software that loads its configuration from a
> properties-style config file specified as the command-line argument. The
[quoted text clipped - 37 lines]
> Line 102 is:
> System.setProperty(key, value);
You might consider making a singleton class with a Properties object
static methods that offer access to the things your application's
classes need -- getProperty() and setProperty() methods and anything
else relevant. Add error handling as appropriate. And add
initialization code as needed, so that your initial set of configurable
properties are loaded when your app is loaded by Tomcat.
= Steve =

Signature
Steve W. Jackson
Montgomery, Alabama
Adam Funk - 15 Nov 2005 09:53 GMT
> You might consider making a singleton class with a Properties object
> static methods that offer access to the things your application's
> classes need -- getProperty() and setProperty() methods and anything
> else relevant. Add error handling as appropriate. And add
> initialization code as needed, so that your initial set of configurable
> properties are loaded when your app is loaded by Tomcat.
I'll look into that, although I'm nervous about the warnings in the "Java in
Practice" book about singletons and garbage collection, since I've never
used the singleton approach before.
Thanks,
Adam
Adam Funk - 15 Nov 2005 11:43 GMT
> We're now developing a web application version of the software, and I've
> discovered that the system properties are not writable [1] from an
[quoted text clipped - 3 lines]
> Is it possible to override this -- at least in a limited way?
> If so, how dangerous is it?
I now believe that if a web app could modify the system properties, the
modifications would affect all other apps running in the same Tomcat server
-- because they are all in the same JVM, which has one common set of system
properties. Is that correct?
Thanks,
Adam