How do I set a system property for a web application? I want to use the java.util.logging classes within my web application as my logging framework. In this framework, I set all my logging properties in a properties file. I then want to set the system property �java.util.logging.config.file� to point to this properties file. This system property is used by the logger for initialization. How do I state the system property in web.xml? I don�t want to have to pass in a property through the command line (i.e.: �java �Djava.util�.�). I originally tried the <env-entry> tag, but that didn�t seem to work (I dumped the System.getProperties() values to standard out in a servlet to test). Besides, all the examples I�ve been able to find that use <env-entry> show using a JNDI context to access the variable. I�m assuming that the logging framework is only using System.getProperty(). I then tried the <context-param> tag, with similar results: no success. How do I set a system property for a web application?
Have you tried <init-param> ? in web.xml ? You can use it in your program with ServletConfig object.
UP THE IRONS !
Joined: Sep 16, 2002
Unfortunatly, <init-param> is used on the initialization of a servlet. I want this to be set on an application. You see, I'm creating a tag library and I'm wanting to log some of the actions within the library. That's why I thought <context-param> would have worked. Thanks for the suggestion though.
And instead of sending it into the program with a -D switch, you want to prepare j.u.l.c.file with web.xml...
So at some point you'll need to retrieve that property (from the context-param), probably in a lifecycle listener (there's one for application startup) and use the corresponding System.setProperty() method to place it into the System's property space. That way your code that expects it in System.getProperty() will find it.
Hi I am also having the same problem.I am trying to set a system property to accesss RMI server.I could not able to connect to RMI server.Do i need to plase the java.policy in any specific place??? Kiran
Joined: Sep 16, 2002
Originally posted by Mike Curwen: you say: This system property is used by the logger for initialization.
So you mean that you do this, in your logging initialization...
Actually, I don't do that myself, the logging framework of the JDK expects it. If you look at the javadoc for java.util.logging.LogManager, it describes how LogManager uses this property.
However, I'm now learning that there is no way to directly set a system property from within the web.xml (disapointing). Therefore, I'm going to need to do what Mike suggested: add an application life-cycle servlet, translate the <context-param> into a system property, and then reset the logging configuration using LogManager.readConfiguration(). Thanks for the help, yall (that's supposed to be you-all, rolled together in a Texan-style, which is interesting to hear, coming from a Scottish-Canadian) ;-)
subject: How to set a system property in a web app?