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
Asked
Active
Viewed 2,192 times
-1

sjain
- 1,635
- 9
- 25
- 35
-
Possible duplicate of [read file in classpath](http://stackoverflow.com/questions/734671/read-file-in-classpath) – Dave Cousineau Apr 14 '17 at 20:18
1 Answers
-1
See this answer:
-
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
-
1if 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