This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Servlets and the fly likes Absolute path of a webapp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Absolute path of a webapp" Watch "Absolute path of a webapp" New topic

Absolute path of a webapp

Fernando Dominguez
Ranch Hand

Joined: Sep 01, 2006
Posts: 102


Is there any way to Know the absolute path of the system where the servlet is runnig?

For example /usr/local/tomcat/webapps/aplication/

I need it beacause I have to read some conf files under /aplication/conf/

[BPS: changed subject to more closely match the question]
[ September 01, 2006: Message edited by: Ben Souther ]
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 61092

Have you looked in the ServletContext API?

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Yes, no, and maybe.
All of the above apply.

Java EE (formerly j2ee) webapps can be deployed as a working file system but they don't have to be. They can also be run as packed war files. Also, parts of a webapp can be bundled into jar files.

If your app has been deployed as an exploded file system, ServletContext.getRealPath("/") will return the path to the root of the web application. If not, then there really isn't a filesystem to access. In this case getRealPath will return null.

As Bear mentioned, the best place to find this information is either the API or the Servlet Spec (links to both are in my signature.).

[ September 01, 2006: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Consider Paul's rocket mass heater.
subject: Absolute path of a webapp