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

Using properties.xml file in a jar file

 
manish c
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic