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

Find Tomcat location

 
Mike Jenkins
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64980
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Mike Jenkins
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64980
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again for all info.

I want to use this for File I/O work.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you be doing file/IO work in within the Tomcat directory structure?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic