报告不会从 netbeans JasperReports 加载
大家好,读过这篇文章的人...
我已经用头撞墙和桌子好几天了...我正在 netbeans 项目中使用 JasperReports 创建报告。我不知道发生了什么,但前一秒它正在工作,下一秒我弹出了 2 个警告,现在报告窗口(屏幕打印输出)和 PDF 打印输出将不会加载,除非代码是从开发环境中运行的。
以下是警告: log4j:WARN 找不到记录器 (net.sf.jasperreports.engine.xml.JRXmlDigesterFactory) 的附加程序。 log4j:WARN 请正确初始化 log4j 系统。
我用来编译报告的这行代码引发了警告:
JasperReport jasperReport = JasperCompileManager.compileReport("C:/Report/report1.jrxml");
整个代码块是用于编译和生成报告的内容如下:
public void Print_File() {
try {
String parameter = LoadNum_Text.getText();
String RecordPath = "C:/Report/Created/LoadSheet/";
String name = RecordPath + parameter;
String destinationFile = name + ".pdf";
Map param = new HashMap();
param.put("Load_Number", parameter);
con = DriverManager.getConnection(host, uName, uPass);
String sql = "SELECT * FROM Load_Sheet";
JasperReport jasperReport = JasperCompileManager.compileReport("C:/Report/report1.jrxml");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, param, con);
JasperExportManager.exportReportToPdfFile(jasperPrint, destinationFile);//export dynamic file name
//con.close();
try {
JasperViewer visor = new JasperViewer(jasperPrint, false);
visor.setVisible(true);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}
我以前版本的代码现在也有同样的问题,因为我尝试回滚到它们,并且我还尝试了旧版本的a(以前的版本)是)工作report1.jrxml文件。
我还尝试了在其他地方运行的不同 MYSQL 服务器,只是为了看看这是否是一个潜在的问题,但仍然有相同的最终结果。
我尝试过从 IReport 本身(我用来生成报告的程序)导入库,但也无济于事。
我还下载并尝试了 JasperReport4.5.0 和 3.0.1 的源代码,但效果更小...
您可以提供的任何帮助我将不胜感激...
Hello to all whom read this....
I have been bashing my head against the wall and desk for a few days now.... I am creating a report with JasperReports in a netbeans project. I have no clue what happened but one moment it was working and the next I had 2 WARNings pop up and now the Reports window (Screen Printout) and the PDF printout will not load unless the code is ran from within the Development environment.
Here are the warnings:
log4j:WARN No appenders could be found for logger (net.sf.jasperreports.engine.xml.JRXmlDigesterFactory).
log4j:WARN Please initialize the log4j system properly.
The warnings are thrown by this line of code that I use to compile the report:
JasperReport jasperReport = JasperCompileManager.compileReport("C:/Report/report1.jrxml");
The whole block of code that is used for compiling and generating the report is as follows:
public void Print_File() {
try {
String parameter = LoadNum_Text.getText();
String RecordPath = "C:/Report/Created/LoadSheet/";
String name = RecordPath + parameter;
String destinationFile = name + ".pdf";
Map param = new HashMap();
param.put("Load_Number", parameter);
con = DriverManager.getConnection(host, uName, uPass);
String sql = "SELECT * FROM Load_Sheet";
JasperReport jasperReport = JasperCompileManager.compileReport("C:/Report/report1.jrxml");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, param, con);
JasperExportManager.exportReportToPdfFile(jasperPrint, destinationFile);//export dynamic file name
//con.close();
try {
JasperViewer visor = new JasperViewer(jasperPrint, false);
visor.setVisible(true);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}
Also my previous versions of the code have the same issue now as i have tried rolling back to them and I also tried an old version of a (what used to be) working report1.jrxml file.
I have also tried a different MYSQL server that I had running else where just as a try to see if that was a potential issue, but still had the same end result.
I have tried just importing the libraries from IReport itself (the program i used to generate the report), but also no avail.
I have also downloaded and tried the source for JasperReport4.5.0 as well as 3.0.1 also with even less avail...
Any help that you could provide i would greatly appreciate it...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在您的类路径中添加以下 log4j.xml 文件:
这应该可以解决 log4j.xml 警告,并为您提供有关所发生情况的更多信息(查看 myReport.log,如果您仍然遇到问题,最终将其发布到此处)。
嗨,Erik,我查看了 myReport.log,发现了以下(所有类似的)错误:
所以很多java.lang.NoSuchFieldException(这意味着类的Java运行时调用找不到该方法,如果jasper报表设计器版本与运行时不同,这种情况很常见)。
我怀疑开发环境与您的运行时环境不同,因此请仔细检查两个环境中的 jasper reports 版本是否相同。
您可以做的另一个测试是将开发环境的 myReport.log 与另一个环境的 myReport.log 进行比较,看看两者中是否都有 java.lang.NoSuchFieldException 异常。 (一般来说有什么区别)。
如果您发现它们不同(例如您没有捕获java.lang.NoSuchFieldException),那么嫌疑几乎就是事实。
问候
add the following log4j.xml file in your classpath:
this should solve the log4j.xml WARN and give you more info about what happens (look at myReport.log and eventually post it here if you still have issues ) .
Hi Erik, I looked at myReport.log and I found the following (all similar) errors:
so a lot of java.lang.NoSuchFieldException (which means that the Java runtime invoke of a class cannot find the method, which is quite usual if the jasper report designer version is different from the runtime).
My suspect is that the dev env is different from your runtime environment, so please double check if the jasper reports version is the same in the two environments.
Another test that you could do is to confront the myReport.log of the dev env with the myReport.log of the other env and see if you have the java.lang.NoSuchFieldException exception in both. (and in general what are the differences).
If you find that they are different (for example you don't catch the java.lang.NoSuchFieldException) then the suspect is almost a fact.
regards
添加
发出一些警告后它会正常工作,例如---
add
It will work fine after giving some warning like---
我们在通过 Jasper 导出报告时遇到了类似的问题,在我们的应用程序中,我们有 spring-4.3.2.jar 版本和 jasperreports-5.6.1.jar。
解决方案只是从chartConstantsBean.xml 中删除这些常量,它们无论如何都无法使用。
ChartConstantsBean.xml 位于 jasperreports-chart-themes-5.0.0.jar 中。
我们已经删除了它,它正在运行,没有任何错误或警告。
We have faced similar issues while exporting the report through Jasper, In our application we have spring-4.3.2.jar version and jasperreports-5.6.1.jar.
Resolution is simply to delete these constants from chartConstantsBean.xml, they couldn't be used anyway.
chartConstantsBean.xml is in jasperreports-chart-themes-5.0.0.jar.
We have removed this and it is working without any error or warning.