报告不会从 netbeans JasperReports 加载

发布于 2024-12-29 21:26:54 字数 1833 浏览 0 评论 0原文

大家好,读过这篇文章的人...

我已经用头撞墙和桌子好几天了...我正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

柒夜笙歌凉 2025-01-05 21:26:54

在您的类路径中添加以下 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 警告,并为您提供有关所发生情况的更多信息(查看 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
.....
.....
.....

所以很多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:

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


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

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

错々过的事 2025-01-05 21:26:54

添加

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.

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.
甜心 2025-01-05 21:26:54

我们在通过 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文