File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes getting TOMCAT_HOME inside servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "getting TOMCAT_HOME inside servlet" Watch "getting TOMCAT_HOME inside servlet" New topic

getting TOMCAT_HOME inside servlet

sachin pathak

Joined: Jun 05, 2002
Posts: 27
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

Joined: Dec 22, 2003
Posts: 1
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".
Todd Nist
Ken Robinson
Ranch Hand

Joined: Dec 23, 2003
Posts: 101
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.
I agree. Here's the link:
subject: getting TOMCAT_HOME inside servlet
It's not a secret anymore!