This question already has answers here:
Can't load jrxml located in jar file via JRXmlLoader: getting java.io.FileNotFoundException [duplicate]
(2个答案)
Caused by: java.io.FileNotFoundException error using Jasperreports
(1个答案)
5年前关闭。
我正在尝试编译jasper报告文件(Invoice.jrxml),但出现此FileNotFound Exception错误
变量
该文件位于
src / com.medicam.servlets / Invoice.jrxml
下面是我的代码
堆栈跟踪
(2个答案)
Caused by: java.io.FileNotFoundException error using Jasperreports
(1个答案)
5年前关闭。
我正在尝试编译jasper报告文件(Invoice.jrxml),但出现此FileNotFound Exception错误
变量
sourceFileName
包含文件名该文件位于
src / com.medicam.servlets / Invoice.jrxml
下面是我的代码
String [] prod = request.getParameterValues("prodn[]");
String [] pkgdate = request.getParameterValues("pkgdate[]");
String [] manufact = request.getParameterValues("manufact[]");
String [] exp = request.getParameterValues("exp[]");
String [] batch = request.getParameterValues("batch[]");
String [] unit = request.getParameterValues("unit[]");
String [] qty = request.getParameterValues("qty[]");
String [] subtot = request.getParameterValues("subtot[]");
ArrayList<String> prodname = new ArrayList<String>();
ArrayList<String> packagedate = new ArrayList<String>();
ArrayList<String> manufactdate = new ArrayList<String>();
ArrayList<String> exipry = new ArrayList<String>();
ArrayList<String> batchno = new ArrayList<String>();
ArrayList<String> unitprice = new ArrayList<String>();
ArrayList<String> quantity = new ArrayList<String>();
ArrayList<String> Subtotal = new ArrayList<String>();
Map<String, Object> param = new HashMap<String, Object>();
for(int i=0;i<prod.length;i++)
{
prodname.add(prod[i]);
packagedate.add(pkgdate[i]);
manufactdate.add(manufact[i]);
exipry.add(exp[i]);
batchno.add(batch[i]);
unitprice.add(unit[i]);
quantity.add(qty[i]);
Subtotal.add(subtot[i]);
}
param.put("prodname", prodname);
param.put("pkgdate", packagedate);
param.put("manfdate", manufactdate);
param.put("expdate", exipry);
param.put("batch", batchno);
param.put("unit", prodname);
param.put("qty", quantity);
param.put("subtot", Subtotal);
try {
String sourceFileName = "Invoice.jrxml";
JasperReport jasperReport = JasperCompileManager.compileReport(sourceFileName);
JasperFillManager.fillReportToFile(
sourceFileName, param);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, param, new JREmptyDataSource());
JasperViewer.viewReport(jasperPrint, false);
}
catch (Exception e) {
e.printStackTrace();
}
堆栈跟踪
net.sf.jasperreports.engine.JRException: java.io.FileNotFoundException: Invoice.jrxml (No such file or directory)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:214)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:185)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:176)
at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:172)
at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:459)
at com.medicam.servlets.GenerateReportForPurchase.doPost(GenerateReportForPurchase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.FileNotFoundException: Invoice.jrxml (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:209)
... 29 more
最佳答案
显然,无法通过简单文件名找到报告文件。
尝试以流方式加载。像这样
InputStream is=this.getClass().getResourceAsStream("/com/medicam/servlets/Invoice.jrxml")
JasperReport jasperReport = JasperCompileManager.compileReport(is);
关于java - 贾斯珀报告中的FileNotFoundException ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27656934/
10-10 04:12