i need to read an external XML file from my java application in jar executable file.
If I lunch it from console (java -jar package.jar) it works fine, but if I lunch it by double click (Java Platform SE binary) it don’t work.
I have this problem with relative path.
With absolute path it work in both way.
i need to read an external XML file from my java application in jar
Share
You need to add the (JAR-relative) path to the XML tile to the
Class-Pathentry in theMANIFEST.MFfile. This entry contains information about the JAR’s runtime classpath. Assuming that you’d like to have the XML in the same folder as the JAR file itself, the following suffices:(don’t forget to put a blank line at end of
MANIFEST.MFfile)Then you can obtain it as a classpath resource using
Class#getResource()orClassLoader#getResource(). The first suffices in your case.