JasperReport Exception NoClassDefFoundError: org/apache/commons/collections/ReferenceMap

1.7k views Asked by At

I want to create reports with jasper in java by using eclipse, but I get awalys this exection:

    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections/ReferenceMap
     at net.sf.jasperreports.engine.util.JRSingletonCache.<init>(JRSingletonCache.java:53)
     at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.<clinit>(JRXmlDigesterFactory.java:181)
     at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:205)
     at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:170)
     at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:154)
     at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:146)
     at at.campus02.bp2.knapp.main.testReport.main(testReport.java:27)
    Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections.ReferenceMap
     at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
     ... 7 more

This is my code:

import java.util.HashMap;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.view.JasperViewer;

public class testReport {

 public static void main(String[] args) {
  // TODO Auto-generated method stub

  try {
   String stringPath = System.getProperty("user.dir") +"\\init\\Blank_A4.jrxml";
   //System.out.println(stringPath);  
   HashMap<String, String> param = new HashMap<String, String>();
   
   JasperReport jr = JasperCompileManager.compileReport(stringPath);
   JasperPrint jp = JasperFillManager.fillReport(jr, param);
   JasperExportManager.exportReportToPdf(jp);
//   JasperViewer.viewReport(jp);
   
  } 
  catch (JRException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
}

These are the JARs and class folders in the project:

  • commons-beanutils-1.9.2.jar
  • commons-collections-3.2.1.jar
  • commons-digester-1.8.jar
  • commons-logging-1.2.jar
  • groovy-all_2.0.1.jar
  • jasper-compiler-jdt-5.5.9.jar
  • jasperreports-4.0.0.jar

I hope someone can help me with the problem. Thanks!

0

There are 0 answers