• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Setting and Reading a System Property

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Eddy Lee Sin Ti
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ramesh Kumar
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can set JAVA_OPTS in catalina.sh / .bat
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic