Currently, I can only make my app access to the XML database when the jar file and XML file in the same directory, and what I hope is that there is only one single jar file which includes the XML file. How can I do that?
private String getXmlPath() {
String url = "";
try {
String cp = "Data\\QuestionList.xml";
File f = new File(ClassLoader.getSystemResource("\\").toURI().getPath());
url += f.getPath() + "\\" + cp;
} catch (URISyntaxException ex) {
url="QuestionList.xml";
}
System.out.println(url);
return url;
}
public void classifyQuestionnaire(String path)
throws FileNotFoundException, XMLStreamException, JAXBException {
// Parse the data, filtering out the start elements
XMLInputFactory xmlif = XMLInputFactory.newInstance();
FileReader fr = null;
if (path == null) {
fr = new FileReader(getXmlPath());
} else {
fr = new FileReader(path);
}
XMLEventReader xmler = xmlif.createXMLEventReader(fr);
EventFilter filter = new EventFilter() {
@Override
public boolean accept(XMLEvent event) {
return event.isStartElement();
}
};