我有6个Jasper Reports,正在等待这个代码编译每个,而fillReport使用我传入的参数。我正在使用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) {
}
}
}
当我到达这一行时,它失败了,并说'#34; Source Not Found&#34;并在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$1.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.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.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
我的建设路径