首页 > 解决方案 > 从 Java 调用 JasperReports

问题描述

我正在尝试打印在 Netbeans 8.2 下使用 Jasper Reports 创建的报告,第一个报告它工作了几天,然后它停止工作,我收到一条错误消息

“线程“AWT-EventQueue-0”中的异常 java.lang.NoClassDefFoundError:org/apache/commons/digester/Digester”。

所有 Jasperreports Jar 文件都存在于我的项目目录“库”下。这是我用来从我的应用程序调用 Jasper 报告的代码。

 try {
        DBModule.ConnectDataBase.ConnectDataBase_Method();
        conn = DBModule.ConnectDataBase.ConnectDataBase_Method();

        //Get a stream to read the file
        InputStream is = this.getClass().getClassLoader().getResourceAsStream(reportName);

        JasperPrint jp = JasperFillManager.fillReport(is, null, conn);

        JRViewer jv = new JRViewer(jp);

        JFrame jf = new JFrame();
        jf.getContentPane().add(jv);
        jf.validate();
        jf.setVisible(true);
        jf.setSize(new Dimension(800,600));
        jf.setLocation(300,100);
        jf.setDefaultCloseOperation(2);

    } catch (JRException ex) {
        CustomControls.CustomTools.CustomMsgBox(ex.getMessage());
    }

任何建议...

标签: java

解决方案


您不仅需要“所有 Jasperreports Jar 文件”,还需要一些第三方库。请查看关于库要求的community.jaspersoft.com/wiki/jasperreports-library-requirements 。除非您没有使用 maven 或类似的东西,否则我想您需要将它们复制到您的类路径中。


推荐阅读