wood burning stoves
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
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

Using properties.xml file in a jar file

manish c

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.
David O'Meara

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
It's not a secret anymore!