Below is a working solution for loading a file/XSD from JAR at runtime. Also, to cross check if it worked you can print the content on console.
try {
InputStream is = null;
BufferedReader br = null;
String line;
ArrayList list = new ArrayList();
try {
is = RequestXMLValidator.class.getResourceAsStream("/schemas/wac-querySubscriber.xsd");
br = new BufferedReader(new InputStreamReader(is));
while (null != (line = br.readLine())) {
list.add(line);
}
}
catch (Exception e) {
e.printStackTrace();
}
Iterator it = list.iterator();
System.out.println(" ################Printing Starts ##################### ");
while(it.hasNext()) {
System.out.println(it.next());
}
} catch (Exception e) {
e.printStackTrace();
}
In the above code "RequestXMLValidator" is the name of the class, so just replace it with you class name and "/schemas/wac-querySubscriber.xsd" is the path of the file/XSD in JAR.