Get installation path of web application from class file
Can anybody tell me how I can get the path on disk to the root of my web application from a class file. Im running under Tomcat 5.5 and I have 3 copies of the same webapp under 3 differenet directories:
C:\xxx\dev\yyy
C:\xxx\test\yyy
C:\xxx\prod\yyy
Based on which directory the web-app, I need to do a lookup on a properties file to pull the right jdbc connection to connect to the appropriate database. So it would be similar to using getServletContext().getRealPath("/") from a .jsp file.
Thanks,
Jason
[548 byte] By [
jplusma] at [2007-11-26 22:58:40]

# 2
I tried that but unfortanetly it returns the path to the Tomcat installation :( and the webapps are under a different directory with their appbase specified in Tomcat's server.xml file. So I guess if I could somehow pull each webapps appbase definition from Tomcat's server.xml, that would work too.
Thanks,
Jason
Message was edited by:
jplusm
Message was edited by:
jplusm
# 5
Sorry, obviously I'm not understanding the word "pull" there. I just gave you code so you could read from the properties file that's inside the application where the code is running. Don't know about pulling it, you'll have to explain what that means.
Edit: Okay, it looks like maybe you don't know the name of the resource file. Is that it?
Message was edited by:
DrClap
# 6
Sorry for not clarifying. I have a properties file with name/value pairs. I know where this properties file is and I can do a lookup in it. In this file, I have jdbc connection names which point to corresponding jdbc resources in my context.xml file.
jdbcDevDatabase=jdbc/tfmDev
jdbcTestDatabase=jdbc/tfmTest
jdbcProdDatabase=jdbc/tfmProd
These connections are for dev, test and prod databases. Now based on where the web-app is installed on disk, i.e-dev dir, test dir, prod dir, I want to retrieve the corresponding connection. The problem is I don't know how to get a handle to the web apps real path on disk without access to the request object or using getServletContext().getRealPath("/") which are not available to me in a class file.
Thanks,
Jason