NoClassDefFoundError: org/apache/commons/logging/L

2019-02-11 11:38发布

问题:

I'm new in JasperReports and I want to integrate a JasperReports into my Java program, so when I click print button the program will show the report. But I get a NoClassDefFoundError when I click the button.

Code

JButton btnReport= new JButton("Report");
btnReport.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent arg0) { 
        try{
            String fileName= "src/learnReport/Leaf_Grey.jasper";
            Connection con = connect.getConnect();
            File file = new File(NameFile);
            JasperReport jasperReport = (JasperReport) JRLoader.loadObject(file);
            JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null,con);
            JasperViewer.viewReport(jasperPrint,false);
        } catch(Exception ex){
            System.out.println(ex);
        }
    }   
});

Runtime error

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    at net.sf.jasperreports.engine.util.JRLoader.<clinit>(JRLoader.java:81)
    at learnReport.Learning$6.actionPerformed(Learning.java:195)
    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)

回答1:

You have missed the jar file "org-apache-commons-logging.jar". Load this jar into your project. The Issue going to be resolved.