my dog learned polymorphism*
The moose likes Servlets and the fly likes How to set a system property in a web app? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to set a system property in a web app?" Watch "How to set a system property in a web app?" New topic
Author

How to set a system property in a web app?

JD Glanville
Greenhorn

Joined: Sep 16, 2002
Posts: 22
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?
Sri Basavanahally
Ranch Hand

Joined: Oct 07, 2003
Posts: 75
Have you tried <init-param> ? in web.xml ? You can use it in your program with ServletConfig object.


UP THE IRONS !
JD Glanville
Greenhorn

Joined: Sep 16, 2002
Posts: 22
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.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

<context-param> should suffice quite nicely for what you are doing. How is it not working for you?
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

you say: This system property is used by the logger for initialization.

So you mean that you do this, in your logging initialization...

String the_file = System.getProperty("java.util.logging.config.file");


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.
Kiran Baratam
Greenhorn

Joined: Sep 03, 2003
Posts: 27
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
JD Glanville
Greenhorn

Joined: Sep 16, 2002
Posts: 22
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...

String the_file = System.getProperty("java.util.logging.config.file");

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) ;-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to set a system property in a web app?
 
Similar Threads
Struts Validation in Spring Context
Issue with [env-entry] element in Weblogic 6.1 descriptors...
The requested resource (/mycode/AA) is not available
value for Context.PROVIDER_URL
Possible to set an env-entry to null in my web.xml file?