-1


In Netbeans IDE i am writing a java class which has some method. One method reads a xml file that I put in the src/resources folder. To access this xml I use the path "src/resources/xmlFile.xml". When I run the class from the ID It works fine. No problem.

But I create the jar of the xml file with the classes. This jar is used with some other project This time method is unable to read the xml file.

What relative path I should use so the method will be able to read the xml? or what other solution could be?
Thanks

sjain
  • 1,635
  • 9
  • 25
  • 35

1 Answers1

-1

See this answer:

read file in classpath

Community
  • 1
  • 1
Karussell
  • 17,085
  • 16
  • 97
  • 197
  • Thanks for the reply. I solved my lots of problem, But i could not get the alternative for this. DOMConfigurator.configure(xml_path); here xnl_path(String) is the relative path for the log4j.xml file. can you provide a piece of code that can be used in place of xml_path. – sjain Nov 12 '10 at 11:00
  • ah I see. isn't there a method with a different argument (e.g. InputStream). – Karussell Nov 25 '10 at 17:17
  • 1
    if DOMConfigurator.configure(xml_path); is under your control you should do it via DOMConfigurator.configure(InputStream); get the IS from MyClass.class.getResourceInputStream(classpath) or similar – Karussell Nov 25 '10 at 17:19