When creating a webapp folder structure (web, WEB-INF, META-INF, class, lib, etc) is there a default location for property files?
Looking at a DB Conn Pool and the values of the DB (user, pwd, driver, etc) are in a property file, and the line that calls the file is: InputStream is = getClass().getResourceAsStream("/dbconn.properties")
Is there a default location for peoperty files, as I don't really want the absolute path here.
The files / resources that you want to read using the web application's classloader can be put in classes folder within WEB-INF.
If you want to put your configuration file is some other location .Say you have lots of configuration files for your application and you want to have a separate config directory within WEB-INF for storing all the configuration files ,then use your servletcontext's getResourceAsStream method with the "/WEB-INF/config/app.properties" as parameter to it.
Hope this helps, [ August 02, 2007: Message edited by: Rahul Bhattacharjee ]
So basically by default 'it' looks under the /WEB-INF/classes folder? But if I want a specific folder I can call something like: /WEB-INF/properties/...
So: InputStream is = getClass().getResourceAsStream("/WEB-INF/props/dbconn.properties");
Excelent, just what I needed, I just didn't want to have to put the whole C:/X/Y/Y/1/2/3/... path in.
Joined: Nov 29, 2005
Do not use
InputStream is = getClass().getResourceAsStream("/WEB-INF/props/dbconn.properties");
ServletContext sc = getServletContext(); InputStream is = sc.getResourceAsStream("/WEB-INF/props/dbconn.properties");
Kevin P Smith
Joined: Feb 18, 2005
But it's not a Servlet calling the file, just a DBConnManager for connection pooling
Joined: Nov 29, 2005
Originally posted by Keith Wilson: But it's not a Servlet calling the file, just a DBConnManager for connection pooling
I guess you can do quite a few things for this issue.
Write a singleton and initialize it in the start up servlet with serveltContext as one of the parameters.If you do not have a start up servlet in your application, then you might want to write a context listener for this.Which would lick off the loading the singleton on initialization of the application context.Now this already initialized singleton would be accessible to the DBManger class too and it can use the values from the singleton.
Singleton should use servletContext to read the config file to a properties object.Write a method which would accept a key and return the value after looking up it in the already loaded properties object. [ August 02, 2007: Message edited by: Rahul Bhattacharjee ]