In a POJO inside Java web app, how do I find the path to the root of the running website, so I can read a file there?
Remember, this is in a POJO, so I don't have:
getServletContext()
(like in a servlet)application
(like in a JSP)
I've seen recommendations for System.getProperty("user.dir")
, but this doesn't look right (on my laptop, it returns C:\Program Files\eclipse\eclipse
, which is clearly not what I want).
The app will be deployed to Azure, so I won't technically know the path to the app in advance, this means I can't set it as a property or setting either. I need to produce it out of thin air, in real-time.
Other languages have globals:
- PHP:
$_SERVER['DOCUMENT_ROOT']
- .NET:
AppDomain.Current.BaseDirectory
You can then form a path by combining these values with the relative path from the webroot.
What is the equivalent for Java?