Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

finding properties outside jar files?

 
Geoffrey Falk
Ranch Hand
Posts: 171
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have packaged my application in a jar file.
The application uses the following code to
read from the properties file:
<pre>
InputStream propStream =
getClass().getClassLoader().
getResourceAsStream(propertiesFile);
props.load(propStream);
</pre>
When I run the application, it cannot find the properties file unless I package it inside the jar file. Is there some way to set my classpath so that it can find the properties file outside of the jar file?
Thanks
Geoffrey
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the way that we do it is - we jar the classes up. Then we create a bat file that explicitely calls the class that has the main in it using the properties file as a parameter
myApp.bat
javaw -cp .;app.jar;otherjars; StartThisClass myAppProperties.properties
< end-file>
Then we have the user start the application using an icon pointing at the .bat file
Of course that means that you can not just double click the jar file and expect it to work.
 
Geoffrey Falk
Ranch Hand
Posts: 171
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. But I would rather do it using a classpath that includes the properties file.
I wonder if I am using the wrong ClassLoader?
Secondly, is there a way to set the Classpath in the manifest of the jar file?
Thanks
Geoffrey
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic