报告不会从netbeans JasperReports加载

时间:2021-04-19 21:05:26

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.

我一直在墙上和桌子上猛击头几天....我正在netbeans项目中创建一个JasperReports的报告。我不知道发生了什么,但有一刻它正在工作,下一次我弹出2个WARNings,现在报告窗口(屏幕打印输出)和PDF打印输出将不会加载,除非代码是从开发环境中运行的。

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.

以下是警告:log4j:WARN无法找到logger的附加程序(net.sf.jasperreports.engine.xml.JRXmlDigesterFactory)。 log4j:WARN请正确初始化log4j系统。

The warnings are thrown by this line of code that I use to compile the report:

我用来编译报告的这行代码抛出了警告:

JasperReport jasperReport = JasperCompileManager.compileReport("C:/Report/report1.jrxml");

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.

此外,我以前的代码版本现在有同样的问题,因为我已经尝试回滚它们,我也尝试了旧版本的(以前是)工作的report1.jrxml文件。

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.

我也尝试了一个不同的MYSQL服务器,我在其他地方运行,试着看看这是否是一个潜在的问题,但仍然有相同的最终结果。

I have tried just importing the libraries from IReport itself (the program i used to generate the report), but also no avail.

我试过从IReport本身导入库(我用来生成报告的程序),但也无济于事。

I have also downloaded and tried the source for JasperReport4.5.0 as well as 3.0.1 also with even less avail...

我也下载并尝试了JasperReport4.5.0以及3.0.1的源代码,但是效果更差......

Any help that you could provide i would greatly appreciate it...

你能提供的任何帮助我都会非常感激...

3 个解决方案

#1


0  

add the following log4j.xml file in your classpath:

在类路径中添加以下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>

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 ) .

这应该解决log4j.xml WARN并为您提供更多关于会发生什么的信息(查看myReport.log并最终在此处发布,如果您仍有问题)。


Hi Erik, I looked at myReport.log and I found the following (all similar) errors:

嗨,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.

所以java.lang.NoSuchFieldException很多(这意味着类的Java运行时调用找不到方法,如果jasper报表设计器版本与运行时不同,这是很常见的)。我怀疑dev env与你的运行时环境不同,所以请仔细检查两个环境中jasper报告的版本是否相同。

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.

您可以做的另一个测试是使用另一个env的myReport.log来面对dev env的myReport.log,并查看两者中是否有java.lang.NoSuchFieldException异常。 (一般来说有什么不同)。如果您发现它们不同(例如您没有捕获java.lang.NoSuchFieldException),那么嫌疑人几乎就是事实。

regards

#2


0  

add

spring.jar file
spring-core-3.2.4.RELEASE
swingx-2007_10_07

It will work fine after giving some warning like---

在给出一些警告之后它会正常工作---

log4j:WARN No appenders could be found for logger (net.sf.jasperreports.engine.xml.JRXmlDigesterFactory).
log4j:WARN Please initialize the log4j system properly.

#3


0  

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.

我们在通过Jasper导出报告时遇到了类似的问题。在我们的应用程序中,我们有spring-4.3.2.jar版本和jasperreports-5.6.1.jar。

Resolution is simply to delete these constants from chartConstantsBean.xml, they couldn't be used anyway.

解决方案只是从chartConstantsBean.xml中删除这些常量,无论如何都无法使用它们。

chartConstantsBean.xml is in jasperreports-chart-themes-5.0.0.jar.

chartConstantsBean.xml位于jasperreports-chart-themes-5.0.0.jar中。

We have removed this and it is working without any error or warning.

我们删除了它,它正在运行,没有任何错误或警告。

#1


0  

add the following log4j.xml file in your classpath:

在类路径中添加以下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>

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 ) .

这应该解决log4j.xml WARN并为您提供更多关于会发生什么的信息(查看myReport.log并最终在此处发布,如果您仍有问题)。


Hi Erik, I looked at myReport.log and I found the following (all similar) errors:

嗨,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.

所以java.lang.NoSuchFieldException很多(这意味着类的Java运行时调用找不到方法,如果jasper报表设计器版本与运行时不同,这是很常见的)。我怀疑dev env与你的运行时环境不同,所以请仔细检查两个环境中jasper报告的版本是否相同。

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.

您可以做的另一个测试是使用另一个env的myReport.log来面对dev env的myReport.log,并查看两者中是否有java.lang.NoSuchFieldException异常。 (一般来说有什么不同)。如果您发现它们不同(例如您没有捕获java.lang.NoSuchFieldException),那么嫌疑人几乎就是事实。

regards

#2


0  

add

spring.jar file
spring-core-3.2.4.RELEASE
swingx-2007_10_07

It will work fine after giving some warning like---

在给出一些警告之后它会正常工作---

log4j:WARN No appenders could be found for logger (net.sf.jasperreports.engine.xml.JRXmlDigesterFactory).
log4j:WARN Please initialize the log4j system properly.

#3


0  

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.

我们在通过Jasper导出报告时遇到了类似的问题。在我们的应用程序中,我们有spring-4.3.2.jar版本和jasperreports-5.6.1.jar。

Resolution is simply to delete these constants from chartConstantsBean.xml, they couldn't be used anyway.

解决方案只是从chartConstantsBean.xml中删除这些常量,无论如何都无法使用它们。

chartConstantsBean.xml is in jasperreports-chart-themes-5.0.0.jar.

chartConstantsBean.xml位于jasperreports-chart-themes-5.0.0.jar中。

We have removed this and it is working without any error or warning.

我们删除了它,它正在运行,没有任何错误或警告。