aspose file tools*
The moose likes Servlets and the fly likes Setting and Reading a System Property Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Setting and Reading a System Property" Watch "Setting and Reading a System Property" New topic
Author

Setting and Reading a System Property

Ramesh Kumar
Ranch Hand

Joined: Dec 28, 2004
Posts: 33
Hi Friends,

I have the requirement of storing a system variable either into Catalina.bat or Web.xml and i need to read from my java code. How can i do it?. Any input from you will be great helpful to me.

Ramesh Kumar
Eddy Lee Sin Ti
Ranch Hand

Joined: Oct 06, 2005
Posts: 135
Hi,

For reading servlet configuration parameters, you can use the ServletConfig object to retrieve. For reading web application general parameters, use ServletContext instead.

I don't recommend to use catalina.bat to pass in parameters using java program arguments. Firstly, the security manager of the container might prohibit you from getting or setting the property. You will get an SecurityException if you do so. Next, it might require a different approach when your application migrate to other containers. You might also have maintenance issue when there are lots of parameters to configure.

What kind of properties you referring to? If these are application/domain specific parameters, usually it is better to put them in database.

Hope this helps. Cheers.
[ November 01, 2006: Message edited by: Eddy Lee Sin Ti ]

SCJP, SCWCD, SCJWS, IBM 700,IBM 701, IBM 704, IBM 705, CA Clarity Technical<br /> <br /><a href="http://eddyleesinti.blogspot.com" target="_blank" rel="nofollow">http://eddyleesinti.blogspot.com</a>
Eddy Lee Sin Ti
Ranch Hand

Joined: Oct 06, 2005
Posts: 135
As another thought, you can also use env-entry element in your deployment descriptor to define the environment variable and use JNDI to load them in runtime.

And even more fun if you want to experiment with MBeans to manage your resources like parameters.

Check this out: Mbeans and Tomcat
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61206
    
  66

RAMESH KUMAR, could you do us all a favor and modify your display name to be mixed case rather than all uppercase? Our eyes will thank you.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ramesh Kumar
Ranch Hand

Joined: Dec 28, 2004
Posts: 33
Hi Friends,

Thanks for your Reply. My Requirement is i have a project specific varable.eing it is a singl variable i can not use properties file. Being the file where i want to read that variable is not a servlet i can not use Servlet Context or Servlet Config. If i want put at a place where server reads and provides when i request for that, that solves my problem.

Please let me know if any solution.


Thanks
Ramesh
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
You can set JAVA_OPTS in catalina.sh / .bat


Rahul Bhattacharjee
LinkedIn - Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting and Reading a System Property