JasperReports 类路径
我想将 .jrxml 文件包含在我的 NetBeans swing 项目中。我使用 NetBeans 7.0.1。我在源包内创建了一个名为“rep”的包,并创建了一个名为“rp.jrxml”的简单 .jrxml 文件。 我已在 NetBeans 中安装了 iReport 插件。当我设置外部 .jrxml 文件时,它会显示(“D:/MyReports/firstreport.jrxml”),但当我设置 NetBeans 包路径时,它不会显示显示。这是我的代码。
try {
String reportSource="/rep/rp.jrxml"; //and also "rep/rp.jrxml" is used.no result.
Map<String, Object> params = new HashMap<String, Object>();
JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, new JREmptyDataSource());
JasperViewer.viewReport(jasperPrint, false);
} catch (Exception e) {e.printStackTrace();
}
然后给出以下错误;
net.sf.jasperreports.engine.JRException: java.io.FileNotFoundException: rep\rp.jrxml (The system cannot find the path specified)
如何将 jrxml 文件保留在我的 NetBeans 项目中并在项目中使用 jrxml 文件?
I want to include the .jrxml file in my NetBeans swing project. I use NetBeans 7.0.1. I created a package inside source package called "rep" and created a simple .jrxml file called "rp.jrxml".
I have installed the iReport plugin in NetBeans. When I set a outer .jrxml file, it is showed ("D:/MyReports/firstreport.jrxml") but when I set the NetBeans package path, it was not shown. Here is my code.
try {
String reportSource="/rep/rp.jrxml"; //and also "rep/rp.jrxml" is used.no result.
Map<String, Object> params = new HashMap<String, Object>();
JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, new JREmptyDataSource());
JasperViewer.viewReport(jasperPrint, false);
} catch (Exception e) {e.printStackTrace();
}
Then the following error is given;
net.sf.jasperreports.engine.JRException: java.io.FileNotFoundException: rep\rp.jrxml (The system cannot find the path specified)
How I can keep jrxml files inside my NetBeans project and use jrxml files inside the project?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此代码适用于我:
我的项目结构:
更新:
为了解决
net.sf.jasperreports.engine.JRException: No report compiler set for language : null
问题,您可以尝试设置groovy
报告语言并添加groovy- all-jdk14
库到类路径。您可以在此处获取groovy库。
语言设置为 groovy 的报表标题示例:
This code works for me:
My project structure:
UPDATED:
For solving
net.sf.jasperreports.engine.JRException: No report compiler set for language : null
problem you can try to setgroovy
report language and addgroovy-all-jdk14
library to classpath.You can get groovy library here.
The sample of report header with language set to
groovy
:这里是解决方案。最好在 jar 文件本身中提供绝对路径。另外,当运行 jar 时,最好使用 *.jasper 文件而不是 .jrxml,它也可能会导致生成报告的速度然后 .jasper 可以作为输入流发送到 JasperFillManager。就是这样。
Here the solution.It is better to provide an absolute path in the jar file itself.Also when the jar is run,using *.jasper file is better to use instead of .jrxml it may cause for the speed of generating the report as well.Then that .jasper can be sent to JasperFillManager as a inputstream. That is it.