I am writing a java servlet that should generate a jasper report. I have stored the jrxml under the WebContent folder in a folder named jrxml (WebContent/jrxml/theFile.jrxml). First I used the following code to generate the report:
InputStream input = new FileInputStream(new File("/jrxml/employeesList.jrxml"));
JasperDesign jasperDesign = JRXmlLoader.load(input);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
However, I kept getting a "No such file or directory" error message. So I then used the following code which I took from Accessing properties file in a JSF application programmatically :
String path = "/jrxml/employeesList.jrxml";
ClassLoader loader = Thread.currentThread().getContextClassLoader();
InputStream input = loader.getResourceAsStream(path);
JasperDesign jasperDesign = JRXmlLoader.load(input);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
Now I no longer get a "No such file or directory" error message, but instead I get "net.sf.jasperreports.engine.JRException: java.net.MalformedURLException" exception, and according to the stack trace it is being cause by the fourth command (JRXmlLoader.load(input)). Can someone please tell me what I'm doing wrong?
Thanks