Reputation: 899
I have Java EE application and in one of its servlets I am using
System.getProperty("user.dir")
but this returns me my eclipse directory not the project directory !
for testing this I created a test project.. a stand alone Java application project in eclipse and used the same code and it returns the path of the project directory ! (this is what I want)
Question : why the behavior is diff ? how in my servlet can I get path of the project directory ?
Upvotes: 0
Views: 1602
Reputation: 236034
For accessing the path of the project directory from a servlet, try this:
request.getSession().getServletContext().getRealPath("/")
Other than that, System.getProperty("user.dir")
is in fact working as expected, returning the user working directory (which is not necessarily the same as the project's directory). Please read the documentation first.
Upvotes: 4
Reputation: 22692
If you actually read the documentation it says this:
user.dir The current working directory when the properties were initialized
Sounds like it's working as expected to me...
From here: http://www.mindspring.com/~mgrand/java-system-properties.htm
Upvotes: 2