Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting TOMCAT_HOME inside servlet

 
sachin pathak
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I get value of a system variable TOMCAT_HOME from inside the servlet. To generalise the question I would say how do you get the value of any environment variable defined by the system
 
Benjiman Bear
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sachin Pathak,
You can use the following to obtain an environment variable:
public static String TOMCAT_HOME = System.getProperty("catalina.home");
The above will return the TOMCAT_HOME, but you can substitute any valid environment value for "catalina.home" to retreive the setting, i.e. "java_home".
HTH.
Regards,
Todd Nist
 
Ken Robinson
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't mind, please outline why you would want to do this?
If you decide later to use an other web container, this code will not work. If you need to find the base directory of your web app, use the ServletContext.getResourceAsStream() method, or the class loader's getResourceAsStream method. It's far more portable.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic