找不到 Jasper Report (.jrxml) 源路径

Cannot locate Jasper Report (.jrxml) source path

我有 6 个 Jasper 报告,它们正在等待此代码编译每个报告,并使用我传入的参数填充报告。我正在使用 Eclipse 并使用 Jaspersoft Studio 创建报告。

public class PrintCertificate { 
private static Connection con = null;

public PrintCertificate( String certType, String firstName, String lastName, String confirmDate, String managerName) {
    DbWorker db = new DbWorker();

    try {
        con = DriverManager.getConnection("jdbc:mysql://localhost:3306/db", "root", "password");
    } catch (Exception e) {
        new DbConnectErrorDialog().setVisible(true);
    }
    String OUT_PUT = "C:/tmp/" + firstName.toLowerCase() + "_" + lastName.toLowerCase() + "_" + certType + ".docx";
    String REPORT = "";

    if(certType.equals("rci_eng")) {
        REPORT = "./certificates/RCI_Eng.jrxml";
    } else if(certType.equals("rci_span")) {
        REPORT = "./certificates/RCIA_Span.jrxml";
    } else if(certType.equals("confirm_eng")) {
        REPORT = "./certificates/Confirm_Eng.jrxml";
    } else if(certType.equals("confirm_span"))  {
        REPORT = "./certificates/Confirm_Span.jrxml";
    } else if(certType.equals("comm_eng")) {
        REPORT = "./certificates/Comm_Eng.jrxml";
    } else if(certType.equals("comm_span")) {
        REPORT = "./certificates/Comm_Span.jrxml";
    }

        HashMap<String, Object> map = new HashMap<>();
        map.put("FirstName",firstName);
        map.put("LastName",lastName);
        map.put("ManagerName", managerName);
        map.put("DateOfConfirmation", confirmDate);

        try  {
            JasperReport jr = JasperCompileManager.compileReport(ClassLoader.getSystemResourceAsStream(REPORT));
            JasperPrint jp = JasperFillManager.fillReport(jr, map, con);
            JRDocxExporter export = new JRDocxExporter();
            export.setExporterInput(new SimpleExporterInput(jp));
            export.setExporterOutput(new SimpleOutputStreamExporterOutput(new File(OUT_PUT)));
            SimpleDocxReportConfiguration config = new SimpleDocxReportConfiguration();
            export.setConfiguration(config);
            export.exportReport();
        } catch (JRException ex) {
        }
}
}

当我到达这一行时失败,并显示 "Source Not Found" 并在 EventDispatchThread.pumpOneEventForFilters(int) 行失败:不可用

JasperReport jr = JasperCompileManager.compileReport(ClassLoader
.getSystemResourceAsStream(REPORT));

这让我相信这是因为 REPORT(jrxml 的路径)错误。 PrintCertificate.java,报告位于:

/src/print/PrintCertificate.java

/src/certificates/RCI_Eng.jrxml

设置REPORT时我使用了正确的路径吗?

我的错误:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/commons/digester/Digester
at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:288)
at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:575)
at print.PrintCertificate.<init>(PrintCertificate.java:75)
at print.Print.actionPerformed(Print.java:147)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access0(Unknown Source)
at java.awt.EventQueue.run(Unknown Source)
at java.awt.EventQueue.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.run(Unknown Source)
at java.awt.EventQueue.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException:    org.apache.commons.digester.Digester
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 40 more

我的构建路径

您应该有以下库来 运行 典型的 Jasper 报告。

你为什么要放 .在 "REPORT = "./certificates/Confirm_Eng.jrxml";"小路。给出不带 .