I am trying to retrieve a jrxml file in a relative path using the following java code:
String jasperFileName = "/web/WEB-INF/reports/MemberOrderListReport.jrxml";
File report = new File(jasperFileName);
FileInputStream fis = new FileInputStream(report);
However, most probably I didn’t succeed in defining the relative path and get an java.io.FileNotFoundException: error during the execution.
Since I am not so experienced in Java I/O operations, I didn’t solve my problem. Any helps or ideas are welcomed.
You’re trying to treat the
jrxmlfile as an object on the file-system, but that’s not applicable inside a web application.You don’t know how or where your application will be deployed, so you can’t point a
Fileat it.Instead you want to use
getResourceAsStreamfrom theServletContext. Something like:is what you’re after.