Hot questions for Using JasperReports in noclassdeffounderror

Top Java Programmings / JasperReports / noclassdeffounderror

Question:

I am getting java.lang.NoClassDefFoundError: org/apache/commons/digester/Digester error and I am stuck with this error for more than a month. I have tried all Digester versions available and I also checked for duplicate JARs in classpath.

I have designed the report through iReport-5.6.0 and I used the JARs from the iReport-5.6.0\ireport\modules\ext and other required JARs.

Error-Log:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/digester/Digester
    at net.sf.jasperreports.engine.JasperCompileManager.compileReportToFile(JasperCompileManager.java:108)
    at net.sf.dynamicreports.examples.JasperMongoDBConnection.main(JasperMongoDBConnection.java:30)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.digester.Digester
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at sun.misc.Launcher$ExtClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 2 more

Answer:

If NoClassDefFoundError is thrown you should check that needed jars are properly loaded in the classpath, or maybe you are mixing versions and class names may be different (or it's behavior). Check if the Digester jar you are adding is the one that is needed.

Check if these jar are correctly loaded:

jasperreports-.jar;
jasperreports-javaflow.jar;
commons-beanutils.jar;
commons-collections.jar;
commons-logging.jar;
commons-digester.jar

Take a look on jasper report plugin folder under your eclipse instance. Search for the commons digester jar inside this folder and copy the same jar (and the other of listed jars) in your project.

Question:

Recently we integrated JasperReports to our enterprise application. Some of our users get java.lang.NoClassDefFoundError: org/springframework/core/io/Resource at client side which is a Swing application. The jnlp file contains jasperreports.jar and no import of this class occurs in our code. Why does JasperReports try to load this class ?


Answer:

The spring-core.jar is an optional jasper report dependency

Why is it trying to load it?,

I would check the jrxml files and the jasperreports_extension.properties.

Question:

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)

Answer:

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

Question:

I have included the Jasperstudio 6.1.1 plugin to my eclipse. I have included the following jars to my lib.

  • jasperreports-6.1.1
  • commons-beanutils-1.8.0
  • commons-collections-2.1
  • commons-digester-1.7
  • commons-loggin-api-1.0.2
  • groovy-all-1.7.5
  • iText-4.2.0
  • ojdbc6

I am getting the followingerror when I tried to execute a stand alone java class. I think the error is because of my commons version but not sure how to find the exact vrsion.

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections/map/ReferenceMap
    at net.sf.jasperreports.engine.design.JRAbstractJavaCompiler.<clinit>(JRAbstractJavaCompiler.java:74)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at net.sf.jasperreports.engine.JasperCompileManager.getCompiler(JasperCompileManager.java:823)
    at net.sf.jasperreports.engine.JasperCompileManager.getEvaluator(JasperCompileManager.java:380)
    at net.sf.jasperreports.engine.fill.JRFillDataset.createCalculator(JRFillDataset.java:467)
    at net.sf.jasperreports.engine.fill.BaseReportFiller.<init>(BaseReportFiller.java:152)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:236)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:72)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:60)
    at net.sf.jasperreports.engine.fill.JRFiller.createBandReportFiller(JRFiller.java:201)
    at net.sf.jasperreports.engine.fill.JRFiller.createReportFiller(JRFiller.java:216)
    at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:85)
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:456)
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:417)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:838)
    at id.hans.employee.application.MainApplication.showReport(MainApplication.java:59)
    at id.hans.employee.application.MainApplication.main(MainApplication.java:83)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections.map.ReferenceMap
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 20 more

Answer:

I just found the solution.The problem was with commons-collect version. I upgraded it to commons-collection-3.2.1.jar and it worked. Thanks

Question:

we have a strange behaviour in a barely new downloaded TomEE Application Server. Our Situation: We have running two applications (lets call it v1 and v2) which provide us some pdf files by a REST API which uses JasperReports. As we released v1 everything worked fine.

As we updated some internal code and released it as v2 the chaos began... (The changes in our code are barely not the origin of our problem, these are only calculating changes.)

Our chaos is, that when we access our code in v1 first, our Reports gets provided fine by v1 API. When we try to get our new Report from v2 API, we run into a class not Found Exception.

Exception in thread "AsyncFileHandlerWriter-2081853534" java.lang.NoClassDefFoundError: Could not initialize class net.sf.jasperreports.extensions.ExtensionsEnvironment
    at net.sf.jasperreports.engine.DefaultJasperReportsContext.getExtensions(DefaultJasperReportsContext.java:277)
    at net.sf.jasperreports.engine.util.MessageUtil.getMessageProvider(MessageUtil.java:70)
    at net.sf.jasperreports.engine.JRRuntimeException.resolveMessage(JRRuntimeException.java:166)
    at net.sf.jasperreports.engine.JRRuntimeException.getMessage(JRRuntimeException.java:147)
    at net.sf.jasperreports.engine.JRRuntimeException.getMessage(JRRuntimeException.java:138)
    at java.base/java.lang.Throwable.getLocalizedMessage(Throwable.java:396)
    at java.base/java.lang.Throwable.toString(Throwable.java:485)
    at java.base/java.lang.String.valueOf(String.java:2801)
    at java.base/java.lang.StringBuilder.append(StringBuilder.java:135)
    at java.base/java.lang.Throwable.printEnclosedStackTrace(Throwable.java:699)
    at java.base/java.lang.Throwable.printEnclosedStackTrace(Throwable.java:713)
    at java.base/java.lang.Throwable.printStackTrace(Throwable.java:671)
    at java.base/java.lang.Throwable.printStackTrace(Throwable.java:725)
    at org.apache.juli.OneLineFormatter.format(OneLineFormatter.java:150)
    at org.apache.juli.FileHandler.publish(FileHandler.java:294)
    at org.apache.juli.AsyncFileHandler.publishInternal(AsyncFileHandler.java:146)
    at org.apache.juli.AsyncFileHandler$LogEntry.flush(AsyncFileHandler.java:185)
    at org.apache.juli.AsyncFileHandler$LoggerThread.run(AsyncFileHandler.java:161)

That far we thought about missing dependencys or missing libs, but: When we acces v2 API first, we get same Error in our v1 API.

So it seems that the API-Application which gets called first "binds" the JasperStuff and die other API cannot access it. We are actually ended with our knowledge and we hope we can get som help here.

A little Background information: We use a core package which provides some core functionality like DB-Access and JDNI Resources, CORS Filter and Security Interfaces. I don't think that core package (provided in each war separately) causes some chaos, but due to the fact that we have amongst other things 2 JDNI resources with the same name (but in diffrent applications and so in diffrent context) i think i need to leave this informatoin here.

Thank you in advance for your help.


Answer:

So after struggeling a bit around and trying diffrent ways to solve the problem we finally found a working solution: We included our JasperReports (and necessary depending) libs to tomcats common.loader property.

The effect is, that we do not have concurring JasperReports libs (altough they're same version). It is a little confusing for me that this should be the reason, but it brings us the expected result. The hint to do so was the AsyncFileHandlerWriter and the "feeling" that the first used context could work fine with the JasperReports libs. It felt a little bit like context concurrency but to be honest we're not sure if this is the correct solution or just a workaround for an underlaying problem.

If someone has further hints we appreciate every hint! Thanks in advance.

Question:

I need to use JasperReport. I had used IReport5.5 some time ago, but now with Java 8 iReport does not run. Instead, I installed JasperSoftStudio 6.3.1 to design my jrxml files.

The Problem is that before I used the jasperreport 5.2 that accept very well for the java code:

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JRExporter;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.export.JRPdfExporter;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.view.JasperViewer;
import net.sf.jasperreports.engine.JasperCompileManager;

public class Main {

    public static void main(String[] argv) throws Exception {

        Class.forName("org.postgresql.Driver");
        Connection conexion = DriverManager.getConnection(
                "jdbc:postgresql://127.0.0.1:5432/database", "postgres",
                "password");


        JasperCompileManager.compileReportToFile(
                "input.jrxml",
                "input.jasper");

        JasperReport reporte = (JasperReport) JRLoader.loadObject("input.jasper");
        JasperPrint jasperPrint = JasperFillManager.fillReport(reporte, null, conexion);

        JRExporter exporter = new JRPdfExporter();

        exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
        exporter.setParameter(JRExporterParameter.OUTPUT_FILE, new java.io.File("output.pdf"));
        exporter.exportReport();


    }
}

However, designing my reports with JasperSoftStudio the old version of jasperreport 5.2 does not accept it. I update my jasperversion to 6.3.0 from https://sourceforge.net/projects/jasperreports/files/jasperreports/ but now the function loadObject is deprecated. Searching a posible solution a found in http://amanuva.blogspot.cl/2016/10/060-conexion-con-informes-desde-java.html the following way

import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;


public class JavaMainClass {
    public static void main(String[] argv) throws Exception {
        Class.forName("org.postgresql.Driver");
        Connection conexion = DriverManager.getConnection(
                "jdbc:postgresql://127.0.0.1:5432/database", "postgres",
                "password");

        JasperReport jasperReport = JasperCompileManager.compileReport("input.jrxml");
        JasperPrint jprint = (JasperPrint) JasperFillManager.fillReport("input.jasper", null, conexion);
        JasperExportManager.exportReportToPdfFile(jprint, "output.pdf");

    }
}

But, I get this error

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    at net.sf.jasperreports.engine.util.JRLoader.<clinit>(JRLoader.java:81)
    at net.sf.jasperreports.engine.JRPropertiesUtil.loadProperties(JRPropertiesUtil.java:102)
    at net.sf.jasperreports.engine.DefaultJasperReportsContext.initProperties(DefaultJasperReportsContext.java:99)
    at net.sf.jasperreports.engine.DefaultJasperReportsContext.<init>(DefaultJasperReportsContext.java:76)
    at net.sf.jasperreports.engine.DefaultJasperReportsContext.<clinit>(DefaultJasperReportsContext.java:59)
    at net.sf.jasperreports.engine.JasperCompileManager.getDefaultInstance(JasperCompileManager.java:200)
    at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:575)
    at JavaMainClass.main(JavaMainClass.java:57)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
    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)
    ... 13 more

Any suggestion is welcome


Answer:

You seem to be missing the Apache commons-logging library from your classpath. Are you using a dependency management tool like Maven? If not, it might be a good time to start... :)

Question:

Can you please guide which jar file need to be included to resolve this error in jasper compilation env. I am using iReport version 3.7.6

java.lang.NoClassDefFoundError:  it/businesslogic/ireport/IReportScriptlet 
at java.lang.ClassLoader.defineClass1(Native Method) 
at java.lang.ClassLoader.defineClass(ClassLoader.java:791) 
at java.lang.ClassLoader.defineClass(ClassLoader.java:634) 

Answer:

I included iReport-1.3.1.jar file and issue vanished