aspose file tools*
The moose likes Tomcat and the fly likes Find Tomcat location Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Find Tomcat location " Watch "Find Tomcat location " New topic
Author

Find Tomcat location

Mike Jenkins
Ranch Hand

Joined: Jul 23, 2006
Posts: 57
Is there a method or something I can use in my Java helper class to find the Tomcat Home location on the server?
For example here is what the path might look like on the Server: C:\TomcatHome\webapps\myfile.jsp

In other language like Cold Fusion I can put in something like ExpandPath function and it will grab the Server Cold Fusion JRUN location: #ExpandPath#webapps\myfile.jsp

Does Java have anything like that?
[ May 05, 2008: Message edited by: Mike Jenkins ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61226
    
  66

Are you really looking for the location of the Tomcat installation, or the location of the web app (which may or may not be co-located)? If the former, I hear many whistles and see many red flags. What would you do with this information?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mike Jenkins
Ranch Hand

Joined: Jul 23, 2006
Posts: 57
Originally posted by Bear Bibeault:
Are you really looking for the location of the Tomcat installation, or the location of the web app (which may or may not be co-located)? If the former, I hear many whistles and see many red flags. What would you do with this information?


Thanks,

I need the location of the Tomcat installation only.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I just tried this on a Linux box and a Windows box (with Tomcat installed and running as a service) and it worked.
In both cases it was Tomcat 5.5



Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

One thing to keep in mind.
Tomcat can be configured to run multiple instances from the same code base.
When doing this, the admin will typically set up a TOMCAT_HOME and, for each instance, a TOMCAT_BASE environment variable (it might be the other way around but the point is the same) so the value returned might not always be what you're looking for.

With disk space being so cheap these days, it's probably somewhat rare to see a configuration like this.


Another thought is that a good administrator will be sure to run Tomcat under a security manager with a policy that doesn't allow calls to System and, in particular, System.getProperties

What you want to do might not be possible in all environments.

-Ben
[ May 05, 2008: Message edited by: Ben Souther ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61226
    
  66

Originally posted by Ben Souther:
What you want to do might not be possible in all environments.
As I said: red flags. What is it you are actually trying to accomplish?
Mike Jenkins
Ranch Hand

Joined: Jul 23, 2006
Posts: 57
Thanks again for all info.

I want to use this for File I/O work.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Why would you be doing file/IO work in within the Tomcat directory structure?
 
 
subject: Find Tomcat location