Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can't find properties file in a particular directory.  RSS feed

 
Jay Newberg
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following are my commands to run:



I have a file called global.properties in /home/dev/App/java/conf. I notice that if I put the global.properties file in "." directory the Controller class reads it fine. However if I just put the global.properties file in /home/dev/App/java/conf, it doesn't get picked up for some reason. I've verified that I have the correct directory in my class path and verified that via the file system the full path to the global.properties file is valid. Any reason for this issue possibly?
 
Jay Newberg
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So it appears I was assuming that global.properties would be picked up simply because it was sitting in a classpath. That turned out to not be the case. I had to add the full path to this properties file to get this to work which makes some sense since Property.load() needs new FileInputStream to pick it up.

HTH anyone else searching for this sort of thing.

JN
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that you can locate the properties file (or any file, for that matter) relative to the classpath, and this is often a preferred.

http://docs.oracle.com/javase/6/docs/api/java/lang/Class.html#getResourceAsStream(java.lang.String)
http://docs.oracle.com/javase/6/docs/api/java/lang/ClassLoader.html#getResourceAsStream(java.lang.String)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!