We have been using System.getProperties("user.dir") to get the location of a properties file. Now that it has been deployed on Tomcat(via servlet), the System call is giving the location as tomcat and not at the location at where the properties file exist.
How can we call the the properties file dynamically?
Given:
- Tomcat is not the only way the app will be deployed
- We have no control on where the app may be placed.
- Relative paths will not work as that Vista is being used and Vista breaks relative paths.
- This must work on all OS, including(but not limited to) Linux, XP and Vista.
- EDIT I implied this, but in case I was not clear enough, I have no way of knowing the path String.
You must have a way of knowing the path of the property file which you can then wrap in a File and pass to the load() method of your properties object.
If you run inside a Tomcat service you are not running as the user you installed it as,so you cannot derive the home directory. You most likely need to hardcode SOMETHING then.
Edit: The property file is relative to the application. See http://www.exampledepot.com/egs/java.lang/ClassOrigin.html for an example of how to get to the file name for the bytecode for a given class. You should be able to continue from there.
You should be aware that some security managers disallow this.