大家好。。。。
几天来,我一直用头撞墙和桌子。。。。我正在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);
}
}
此外,我以前版本的代码现在也有同样的问题,因为我已经尝试回滚到它们,我还尝试了一个旧版本的(过去的)工作report1.jrxml文件。
我还尝试了一个不同的MYSQL服务器,我在其他地方运行过,只是想看看这是否是一个潜在的问题,但最终结果仍然相同。
我试过从IReport本身(我用来生成报告的程序)导入库,但也没有用。
我还下载并尝试了JasperReport4.5.0和3.0.1的源代码,但收效甚微。。。
如果您能提供任何帮助,我将不胜感激…
在类路径中添加以下log4j.xml文件:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="CA" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-4r [%t] %-5p %c %x - %m%n" />
</layout>
</appender>
<appender name="FA" class="org.apache.log4j.FileAppender">
<param name="File" value="myReport.log"/>
<param name="Threshold" value="ALL"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-4r [%t] %-5p %c %x - %m%n" />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="CA" />
<appender-ref ref="FA" />
</root>
</log4j:configuration>
这将解决log4j.xml WARN问题,并为您提供有关所发生情况的更多信息(如果您仍然有问题,请查看myReport.log并最终将其发布在此处)。
嗨,Erik,我查看了myReport.log,发现了以下(所有类似的)错误:
5072 [AWT-EventQueue-0] DEBUG org.springframework.beans.factory.xml.XmlBeanFactory - Ignoring bean creation exception on FactoryBean type check: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'titleBaseFontSize': Invocation of init method failed; nested exception is
java.lang.NoSuchFieldException: TITLE_BASEFONT_SIZE
5315 [AWT-EventQueue-0] DEBUG org.springframework.beans.factory.xml.XmlBeanFactory - Ignoring bean creation exception on FactoryBean type check: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'subtitleBaseFontSize': Invocation of init method failed; nested exception is
java.lang.NoSuchFieldException: SUBTITLE_BASEFONT_SIZE
5610 [AWT-EventQueue-0] DEBUG org.springframework.beans.factory.xml.XmlBeanFactory - Ignoring bean creation exception on FactoryBean type check: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'legendBaseFontSize': Invocation of init method failed; nested exception is java.lang.NoSuchFieldException: LEGEND_BASEFONT_SIZE
5991 [AWT-EventQueue-0] DEBUG org.springframework.beans.factory.xml.XmlBeanFactory - Ignoring bean creation exception on FactoryBean type check: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'axisLabelFontSize': Invocation of init method failed; nested exception is java.lang.NoSuchFieldException: AXIS_LABEL_FONT_SIZE
6041 [AWT-EventQueue-0] DEBUG org.springframework.beans.factory.xml.XmlBeanFactory - Ignoring bean creation exception on FactoryBean type check: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'axisTickLabelFontSize': Invocation of init method failed; nested exception is java.lang.NoSuchFieldException: AXIS_TICK_LABEL_FONT_SIZE
.....
.....
.....
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
spring.jar file
spring-core-3.2.4.RELEASE
swingx-2007_10_07
它在发出一些警告后会正常工作,比如---
log4j:WARN No appenders could be found for logger (net.sf.jasperreports.engine.xml.JRXmlDigesterFactory).
log4j:WARN Please initialize the log4j system properly.
我们在通过Jasper导出报告时遇到了类似的问题,在我们的应用程序中,我们有spring-4.3.2jar版本和jasperreports-5.6.jar。
解决方案只是从chartConstantsBean.xml中删除这些常量,它们无论如何都无法使用。
chartConstantsBean.xml位于jasperreports-chart-themes-5.0.0.jar中。
我们已经删除了它,它在没有任何错误或警告的情况下工作。