I have a web project which relies on other classes (in my project’s source filder) which require configuration information stored in a properties files. One class that needs its own properties file is not a servlet, and therefore cannot locate the file using the servletContext.
To load the properties file, I can use either of the following code statements:
properties.load(getClass().getResourceAsStream("/myapp.properties"));
or
properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("/myapp.properties"));
If I place the properties file in the source folder, then it gets copied to tomcat’s /WEB-INF/classes, and loads fine.
If I place the properties file in my project’s /WEB-INF/lib directory, then it gets copied to tomcat’s /WEB-INF/lib directory but fails to load.
Is it not the case that the classloader will try loading from either /WEB-INF/classes or /WEB-INF/lib?
I don’t really want the configuration information contained in the properties file to be in a jar file in the lib directiory? Since this file needs to be modified easily according to which app server it gets deployed too. I don’t want the properties file “bound” to the code, but easily modifiable for different server deployements/environments.
Is there some easy way of achieving this?
Thanks
John
Win2k Eclipse 2.1.1 MyEclipse 2.6.1 tomcat 5.0.3