本文介绍了加载jasperreports的.jrxml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In my project I have stored .jrxml files in a package called com/bio/ofm/mnu/views/reports/jasperReports/When I try to load a .jrxml I get following error,

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

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

This is how I load the file,

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");

请帮助

推荐答案

以如下所示的流方式加载文件时,

When loading the file as a stream like below it worked,

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

JasperReport report = JasperCompileManager.compileReport(in);

这篇关于加载jasperreports的.jrxml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 01:13