I have a webapp. I want to load a properties file, but I dont want to hardcode the full path of the properties file. I want to use relative paths under the webapp root. If I load a resource on the classpath such as under /WEB-INF/classes/app.properties, that works fine. But what if the properties file is under a different directory like /WEB-INF/configfiles/ ?
I also don't want to specify /WEB-INF/configfiles/ as part of the classpath when starting up the webapp. Is there a way to do what I want? Thanks.
Originally posted by Venkatraman Kandaswamy: You can try having your config files outside WEB-INF. If you have your files in your-webapp/config folder - you can access the property file in your code as config/properties-file.
when the configuration file is stored under webapp, then it will be accessed easily by anyone who specifies the url to that file, Which is a security leak, if the configuration file has data base information or some other sensitive data.
Do you know why this cup is useful? Because it is empty.
I am not sure of the benefits of having property file outside the classes folder, though it is secure & straightforward. However I am thinking of other ways that you can try (though I myself feel weird of my suggestions :roll: Again it is classpath - inside a jar file in /web-inf/lib. Otherwise keep it in web-inf/config folder and publish it through a dedicated & secured servlet other than your controller. If you are using framework like struts you can do it easily through an action path whose url pattern is protected from public. (have to try out and see) If you could share the reason for keeping the property file outside classes folder, it might be useful for others.
[ February 15, 2008: Message edited by: Ray Johnson ]
[ February 15, 2008: Message edited by: Ray Johnson ] [ February 15, 2008: Message edited by: Ray Johnson ]
"It's been so long since I've done a good thing--the right thing" : Tears Of Sun
The reason is we have properties files and xml config files (lots actually) so we dont just want to dump them under the /WEB-INF/classes folder. So I tried putting them outside but then cant find them anymore in classpath. Dont want to use a startup parameter to add to the classpath either. Main reason to put it outside the /classes folder or /lib is for clarity of organization.
I am also looking for some kind of solution to this problem. I want to keep my .properties files outside the web-app. I have created a new env variable and set the classpath in the server's Startup.sh batch file.
I called the .properties file by using the below code:
InputStream inputStream = getClass().getResourceAsStream("abc.properties");
logger.info("InputStream is: " + inputStream);