1

在我的项目中,我将 .jrxml 文件存储在一个名为 com/bio/ofm/mnu/views/reports/jasperReports/ 的包中,当我尝试加载 .jrxml 时出现以下错误,

net.sf.jasperreports.engine.JRException: java.io.FileNotFoundException: com/bio/ofm/mnu/views/reports/jasperReports/repAuditReport.jrxml (No such file or directory)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:174)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:154)
        at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:146)
        at com.bio.ofm.mnu.views.panels.RepAuditReport$2.run(RepAuditReport.java:87)
        at java.lang.Thread.run(Thread.java:722)
Caused by: java.io.FileNotFoundException: com/bio/ofm/mnu/views/reports/jasperReports/repAuditReport.jrxml (No such file or directory)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:138)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:169)
        ... 4 more

这就是我加载文件的方式,

String fileName = getClass().getClassLoader().getResource("com/bio/ofm/mnu/views/reports/jasperReports/repAuditReport.jrxml").getFile();    

   JasperReport report = JasperCompileManager.compileReport("com/bio/ofm/mnu/views/reports/jasperReports/repAuditReport.jrxml");

请帮忙

4

2 回答 2

3

当将文件加载为如下所示的流时,它起作用了,

InputStream in = this.getClass().getClassLoader().getResourceAsStream("com/bio/ofm/mnu/views/reports/jasperReports/repAuditReport.jrxml");

JasperReport report = JasperCompileManager.compileReport(in);
于 2012-05-22T12:01:59.927 回答
2

我正在这样编译我的报告:

ByteArrayInputStream is = MyRenderer.class.getClassLoader().getResourceAsStream("anytemplate.jrxml");

JasperDesign jasperDesign = JRXmlLoader.load(is);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
于 2015-10-15T08:40:18.767 回答