Properties file problems <-- java newbie
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Randy_Pond
Posted On:   Wednesday, September 19, 2001 10:34 AM

Problems with .properties files. My situation: I keep my database properties in a properties file that is located at the src root. :projectsrcdb.properties. I read the properties by Properties prop = new Properties(new FileInputStream("db.properties"). I have noticed that this code is not that reliable. For example, when I manually run my junit test, it finds the properties file. When I run my junit test from an ant build, it doesn't find the file. My build.xml is located at c:project. When I deploy the application to a web server (tomcat), and run from there, it doesn't find the properties file either. My question: Loading properties file   More>>

Problems with .properties files.



My situation:
I keep my database properties in a properties file that is located at the src root. :projectsrcdb.properties.


I read the properties by Properties prop = new Properties(new FileInputStream("db.properties"). I have noticed that this code is not that reliable.


For example, when I manually run my junit test, it finds the properties file. When I run my junit test from an ant build, it doesn't find the file. My build.xml is located at c:project.


When I deploy the application to a web server (tomcat), and run from there, it doesn't find the properties file either.


My question:
Loading properties files depends on the working directory. Correct? When I move my properties file from c:projectsrc to c:project, the ant build will work correctly.


Is there a way to load properties files so that it doesn't depend on the working directory? So, that it depends on the classpath?


Randy
(Java Noobie trying to learning junit/ant/servlets/jdbc)

   <<Less

Re: Properties file problems &lt;-- java newbie

Posted By:   Anonymous  
Posted On:   Wednesday, September 19, 2001 02:59 PM

You can read the java.class.path property to determine what the classpath is, and then construct an absolute path from there. You can always load a properties file using absolute path
About | Sitemap | Contact