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 Using properties.xml  file in a jar file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Using properties.xml  file in a jar file" Watch "Using properties.xml  file in a jar file" New topic
Author

Using properties.xml file in a jar file

manish c
Greenhorn

Joined: Jan 15, 2004
Posts: 2
I have packaged a properties.xml file along with my class files inside a jar.
My Code uses properites.xml file as following
String propertyFilename = "properties.xml"
InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream(propertyFileName);
....
Document doc = XMLReader.getDocument(is);
....
When I run this code my running class does not find the properties.xml thought the classpath is set to the jar (having the properties.xml file) file in which I packaged my properties.xml and the running class.
using java -classpath C:\.......\build\aipUtil.jar runningclass
If I put the file outside the jar and inside the dir build, then use the classpath
using java -classpath C:\.......\aipUtil.jar;C:\......\build\. runningclass
It works fine.
Can someone please tell me how can I make my code see the properties.xml file inside my code while having the properties.xml file in the same jar.
Manish
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Your properties.xml won't be found by the system classloader, you should use the same ClassLoader that can find your Classes inside the jar. ie just try this.getClass().getClassLoader();
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using properties.xml file in a jar file
 
Similar Threads
packages + classpath
Difference in classpath result between javac and java
About JAR files...
Incompletely deployed packages. Trying to run Struts example from HF servlets 1 Ed.
Ant's classpath vs Eclipse's classpath