• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting and Reading a System Property

 
Ramesh Kumar
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • 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
 
Eddy Lee Sin Ti
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can set JAVA_OPTS in catalina.sh / .bat
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic