aspose file tools*
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "Absolute path of a webapp" Watch "Absolute path of a webapp" New topic
Author

Absolute path of a webapp

Fernando Dominguez
Ranch Hand

Joined: Sep 01, 2006
Posts: 104

Hello,

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
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

Have you looked in the ServletContext API?


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

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.).

Good-Luck
-Ben
[ 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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Absolute path of a webapp