File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes finding properties outside jar files? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "finding properties outside jar files?" Watch "finding properties outside jar files?" New topic
Author

finding properties outside jar files?

Geoffrey Falk
Ranch Hand

Joined: Aug 17, 2001
Posts: 171
    
    1
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


Sun Certified Programmer for the Java 2 Platform
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
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.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Geoffrey Falk
Ranch Hand

Joined: Aug 17, 2001
Posts: 171
    
    1
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: finding properties outside jar files?