aspose file tools*
The moose likes Java in General and the fly likes Lost properties Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Lost properties" Watch "Lost properties" New topic
Author

Lost properties

Kevin P Smith
Ranch Hand

Joined: Feb 18, 2005
Posts: 362
Hi guys,

I'm having a little trouble with a DB conn pool I'm setting up.
The details of the database (name, location, user/pwd, etc) are all stored in a properties file, so that if anything changes, it's a simple change to the properties file rather than code.

Prolem is, I can't find a way of getting this Init class to see the properties file. I don't want a full local path (C:\...\...\...\) I would need it to be a relative path. I have asked about this before and was under the standing that the WEB-INF folder was the place to have properties files, but my class still can not see it

ERROR: FileNotFoundException

CODE:
Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

Is your code inside a servlet? If yes, then you can simply use getServletContext().getResourceAsStream("/WEB-INF/properties/dbconn.properties");


SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
Kevin P Smith
Ranch Hand

Joined: Feb 18, 2005
Posts: 362
Code is not in a Servlet, but is called by a Servlet.

ERROR:


CODE:


SERVLET CALL:


[ August 17, 2007: Message edited by: Keith Wilson ]
[ August 17, 2007: Message edited by: Keith Wilson ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39578
    
  27
getClass().getResource("/WEB-INF/properties/dbconn.properties");

For this to work, the file needs to be in the classpath. Try moving the dbconn.properties file into the "classes" directory (and don't prefix it by "WEB-INF/classes").

Or work with the servlet context, as was suggested before.


Ping & DNS - updated with new look and Ping home screen widget
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Lost properties
 
Similar Threads
a mistake for bean
Properties file
Problem in loading servlet in startup
how to read config file from other mahine using java
relative path name for propertiesObject.load()