This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
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 ]
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 ]