Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get application directory?

Status
Not open for further replies.

SuperMoonster

Programmer
Aug 11, 2005
59
BR
Hello everyone,

I wanna get the directory from where my application is running. Is there a way to do it?
I tried:

System.getProperty("user.dir");



But it returns me my linux user directory (/home/myname).

How can I make it return the dir from where the app is running? Thanks
 
Something like

Code:
java.io.File f = new java.io.File(".");
return f.getCanonicalPath();

would do the trick.

Cheers,
Dian
 
That's a neat trick if it works, Dian. I may use that myself at some point.

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
Is this supposed to work in a web application? For that's my case.

If I use your method in a desktop app, in works. In a web app, it doesn't.
I just wanna get the full path of where my web app is running, something like: /srv/
Is it possible?
 
Oh, then I think that's a question for the J2EE forum or the Tomcat forum, this is for J2SE questions.

Cheers,
Dian
 
Well you did not actually say it was for a webapp did you ?!

From a JSP or servlet :

String webappRoot = getServletContext().getRealPath("/");

will give you :

TOMCAT_HOME/webapps/YourWebApp

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top