You need to add the path (JAR-relative) to the XML fragment to the entry Class-Pathin the file MANIFEST.MF. This entry contains path information for the runtime JAR class. Assuming you want the XML in the same folder as the JAR file itself, enough:
Class-Path: .
(don't forget to put an empty line at the end of the file MANIFEST.MF)
Then you can get it as a classpath resource with Class#getResource()or ClassLoader#getResource(). The first in your case is enough.
URL xmlResource = getClass().getResource("/filename.xml");
File xmlFile = new File(xmlResource.getPath());
source
share