Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / November 2005

Tip: Looking for answers? Try searching our database.

Can't System.setProperty(String, String) in a Tomcat5 web application.

Thread view: 
Adam Funk - 14 Nov 2005 11:39 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
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.