0

I have 6 Jasper Reports, that are waiting on this code to compile each, and fillReport with the parameters i pass in. I am using Eclipse and created the reports with 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) {
        }
}
}

When i get to this line it fails, and says "Source Not Found" and failing at EventDispatchThread.pumpOneEventForFilters(int) line: not available

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

This makes me believe its due to REPORT (the path of the jrxml) being wrong. PrintCertificate.java, and the reports are located at:

/src/print/PrintCertificate.java

/src/certificates/RCI_Eng.jrxml

Did I use the right path when setting REPORT?

My Error:

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

MY BUILD PATH

enter image description here

Alex K
  • 22,315
  • 19
  • 108
  • 236
webminer07
  • 293
  • 4
  • 8
  • 25
  • 1
    You are missing some required libraries on your classpath. Please check the requirements for Jasper and add all required libraries to the classpath of your application. – Mark Rotteveel Nov 28 '15 at 09:16

2 Answers2

1

You should have below libraries to run typical Jasper report.

enter image description here

Madushan Perera
  • 2,568
  • 2
  • 17
  • 36
  • I added all of these libraries and the Jakarta and commons ones that were listed on the Jasper reports requirements http://community.jaspersoft.com/wiki/jasperreports-library-requirements But now it is failing to even load the Main method because it seems like theres conflicts. I am adding an image of my Build Path – webminer07 Nov 28 '15 at 09:51
  • 1
    According to your exception it says `Caused by: java.lang.ClassNotFoundException: org.apache.commons.digester.Digester`. But I can see that lib in your build path. Remove all the unnecessary lib files and try to run again.(Except mysql-driver,jCalender etc..) – Madushan Perera Nov 28 '15 at 10:02
  • I didnt have Apache Ant added. http://ant.apache.org/bindownload.cgi There are 22 JARs included in this. Do i just need ant.jar? or all 22 of them? – webminer07 Nov 28 '15 at 10:16
  • NO. I dont think so.. Dont try to add everything . There are plenty of libraries come with Jasper Report . But you dont need to add them all. Adding unnecessary libraries makes your project heavy. – Madushan Perera Nov 28 '15 at 10:20
0

Why you are putting . in "REPORT = "./certificates/Confirm_Eng.jrxml";" path. Give relative path without .

Ananta Ch. Swain
  • 53
  • 1
  • 2
  • 6