/ java.lang.NoClassDefFoundError: How to resolve – Part 2 ~ Java EE Support Patterns

6.15.2012

java.lang.NoClassDefFoundError: How to resolve – Part 2

This article is part 2 of our java.lang.NoClassDefFoundError troubleshooting series. It will focus on the more simple type of NoClassDefFoundError problem. This article is ideal for Java beginners and I highly recommend that you compile, run and study the sample Java program.
If not done already, I suggest that you first review the java.lang.NoClassDefFoundError - Part 1.

The following writing format will be used going forward and will provide you with:

-        Description of the problem case and type of NoClassDefFoundError.
-        Sample Java program “simulating” the problem case.
-        ClassLoader chain view.
-        Recommendations and resolution strategies.

NoClassDefFoundError problem case 1 – missing JAR file

The first problem case we will cover is related to a Java program packaging and / or classpath problem. A typical Java program can include one or many JAR files created at compile time. NoClassDefFoundError can often be observed when you forget to add JAR file(s) containing Java classes referenced by your Java or Java EE application.

This type of problem is normally not hard to resolve once you analyze the Java Exception and missing Java class name.

Sample Java program

** Tutorial video is now available: http://www.youtube.com/watch?v=Nn_Pq8cWiBg

The following simple Java program is split as per below:

-        The main Java program NoClassDefFoundErrorSimulator
-        The caller Java class CallerClassA
-        The referencing Java class ReferencingClassA
-        A util class for ClassLoader and logging related facilities JavaEETrainingUtil

This program is simple attempting to create a new instance and execute a method of the Java class CallerClassA which is referencing the class ReferencingClassA.It will demonstrate how a simple classpath problem can trigger NoClassDefFoundError. The program is also displaying detail on the current class loader chain at class loading time in order to help you keep track of this process. This will be especially useful for future and more complex problem cases when dealing with larger class loader chains.

#### NoClassDefFoundErrorSimulator.java
package org.ph.javaee.training1;

import org.ph.javaee.training.util.JavaEETrainingUtil;

/**
 * NoClassDefFoundErrorTraining1
 * @author Pierre-Hugues Charbonneau
 *
 */
public class NoClassDefFoundErrorSimulator {
       
       
        /**
         * @param args
         */
        public static void main(String[] args) {
               System.out.println("java.lang.NoClassDefFoundError Simulator - Training 1");
               System.out.println("Author: Pierre-Hugues Charbonneau");
               System.out.println("http://javaeesupportpatterns.blogspot.com");
              
               // Print current Classloader context
               System.out.println("\nCurrent ClassLoader chain: "+JavaEETrainingUtil.getCurrentClassloaderDetail());
              
               // 1. Create a new instance of CallerClassA
               CallerClassA caller = new CallerClassA();
              
               // 2. Execute method of the caller
               caller.doSomething();
              
               System.out.println("done!");
        }
}


#### CallerClassA.java
package org.ph.javaee.training1;

import org.ph.javaee.training.util.JavaEETrainingUtil;

/**
 * CallerClassA
 * @author Pierre-Hugues Charbonneau
 *
 */
public class CallerClassA {
       
        private final static String CLAZZ = CallerClassA.class.getName();
       
        static {
               System.out.println("Classloading of "+CLAZZ+" in progress..."+JavaEETrainingUtil.getCurrentClassloaderDetail());
        }
       
        public CallerClassA() {
               System.out.println("Creating a new instance of "+CallerClassA.class.getName()+"...");
        }
       
        public void doSomething() {
              
               // Create a new instance of ReferencingClassA
               ReferencingClassA referencingClass = new ReferencingClassA();             
        }
}

#### ReferencingClassA.java
package org.ph.javaee.training1;

import org.ph.javaee.training.util.JavaEETrainingUtil;

/**
 * ReferencingClassA
 * @author Pierre-Hugues Charbonneau
 *
 */
public class ReferencingClassA {

        private final static String CLAZZ = ReferencingClassA.class.getName();
       
        static {
               System.out.println("Classloading of "+CLAZZ+" in progress..."+JavaEETrainingUtil.getCurrentClassloaderDetail());
        }
       
        public ReferencingClassA() {
               System.out.println("Creating a new instance of "+ReferencingClassA.class.getName()+"...");
        }
       
        public void doSomething() {
               //nothing to do...
        }
}


#### JavaEETrainingUtil.java
package org.ph.javaee.training.util;

import java.util.Stack;
import java.lang.ClassLoader;

/**
 * JavaEETrainingUtil
 * @author Pierre-Hugues Charbonneau
 *
 */
public class JavaEETrainingUtil {
       
        /**
         * getCurrentClassloaderDetail
         * @return
         */
        public static String getCurrentClassloaderDetail() {
              
               StringBuffer classLoaderDetail = new StringBuffer();       
               Stack<ClassLoader> classLoaderStack = new Stack<ClassLoader>();
              
               ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
              
               classLoaderDetail.append("\n-----------------------------------------------------------------\n");
              
               // Build a Stack of the current ClassLoader chain
               while (currentClassLoader != null) {
              
                       classLoaderStack.push(currentClassLoader);
                      
                       currentClassLoader = currentClassLoader.getParent();
               }
              
               // Print ClassLoader parent chain
               while(classLoaderStack.size() > 0) {
                      
                       ClassLoader classLoader = classLoaderStack.pop();
                      
                       // Print current                     
                       classLoaderDetail.append(classLoader);
                      
                       if (classLoaderStack.size() > 0) {
                              classLoaderDetail.append("\n--- delegation ---\n");                               
                       } else {
                              classLoaderDetail.append(" **Current ClassLoader**");
                       }
               }
              
               classLoaderDetail.append("\n-----------------------------------------------------------------\n");
              
               return classLoaderDetail.toString();
        }
}


Problem reproduction

In order to replicate the problem, we will simply “voluntary” omit one of the JAR files from the classpath that contains the referencing Java class ReferencingClassA.

The Java program is packaged as per below:

-        MainProgram.jar (contains NoClassDefFoundErrorSimulator.class and JavaEETrainingUtil.class)
-        CallerClassA.jar (contains CallerClassA.class)
-        ReferencingClassA.jar (contains ReferencingClassA.class)

Now, let’s run the program as is:

## Baseline (normal execution)
..\bin>java -classpath CallerClassA.jar;ReferencingClassA.jar;MainProgram.jar org.ph.javaee.training1.NoClassDefFoundErrorSimulator

java.lang.NoClassDefFoundError Simulator - Training 1
Author: Pierre-Hugues Charbonneau
http://javaeesupportpatterns.blogspot.com

Current ClassLoader chain:
-----------------------------------------------------------------
sun.misc.Launcher$ExtClassLoader@17c1e333
--- delegation ---
sun.misc.Launcher$AppClassLoader@214c4ac9 **Current ClassLoader**
-----------------------------------------------------------------

Classloading of org.ph.javaee.training1.CallerClassA in progress...
-----------------------------------------------------------------
sun.misc.Launcher$ExtClassLoader@17c1e333
--- delegation ---
sun.misc.Launcher$AppClassLoader@214c4ac9 **Current ClassLoader**
-----------------------------------------------------------------

Creating a new instance of org.ph.javaee.training1.CallerClassA...
Classloading of org.ph.javaee.training1.ReferencingClassA in progress...
-----------------------------------------------------------------
sun.misc.Launcher$ExtClassLoader@17c1e333
--- delegation ---
sun.misc.Launcher$AppClassLoader@214c4ac9 **Current ClassLoader**
-----------------------------------------------------------------

Creating a new instance of org.ph.javaee.training1.ReferencingClassA...
done!


For the initial run (baseline), the main program was able to create a new instance of CallerClassA and execute its method successfully; including successful class loading of the referencing class ReferencingClassA.

## Problem reproduction run (with removal of ReferencingClassA.jar)
../bin>java -classpath CallerClassA.jar;MainProgram.jar org.ph.javaee.training1.NoClassDefFoundErrorSimulator

java.lang.NoClassDefFoundError Simulator - Training 1
Author: Pierre-Hugues Charbonneau
http://javaeesupportpatterns.blogspot.com

Current ClassLoader chain:
-----------------------------------------------------------------
sun.misc.Launcher$ExtClassLoader@17c1e333
--- delegation ---
sun.misc.Launcher$AppClassLoader@214c4ac9 **Current ClassLoader**
-----------------------------------------------------------------

Classloading of org.ph.javaee.training1.CallerClassA in progress...
-----------------------------------------------------------------
sun.misc.Launcher$ExtClassLoader@17c1e333
--- delegation ---
sun.misc.Launcher$AppClassLoader@214c4ac9 **Current ClassLoader**
-----------------------------------------------------------------

Creating a new instance of org.ph.javaee.training1.CallerClassA...
Exception in thread "main" java.lang.NoClassDefFoundError: org/ph/javaee/training1/ReferencingClassA
        at org.ph.javaee.training1.CallerClassA.doSomething(CallerClassA.java:25)
        at org.ph.javaee.training1.NoClassDefFoundErrorSimulator.main(NoClassDefFoundErrorSimulator.java:28)
Caused by: java.lang.ClassNotFoundException: org.ph.javaee.training1.ReferencingClassA
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        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)
        ... 2 more


What happened? The removal of the ReferencingClassA.jar, containing ReferencingClassA, did prevent the current class loader to locate this referencing Java class at runtime leading to ClassNotFoundException and NoClassDefFoundError.

This is the typical Exception that you will get if you omit JAR file(s) from your Java start-up classpath or within an EAR / WAR for Java EE related applications.

ClassLoader view

Now let’s review the ClassLoader chain so you can properly understand this problem case. As you saw from the Java program output logging, the following Java ClassLoaders were found:

Classloading of org.ph.javaee.training1.CallerClassA in progress...
-----------------------------------------------------------------
sun.misc.Launcher$ExtClassLoader@17c1e333
--- delegation ---
sun.misc.Launcher$AppClassLoader@214c4ac9 **Current ClassLoader**
-----------------------------------------------------------------

** Please note that the Java bootstrap class loader is responsible to load the core JDK classes and is written in native code **

## sun.misc.Launcher$AppClassLoader
This is the system class loader responsible to load our application code found from the Java classpath specified at start-up.

##sun.misc.Launcher$ExtClassLoader
This is the extension class loader responsible to load code in the extensions directories (<JAVA_HOME>/lib/ext, or any other directory specified by the java.ext.dirs system property).

As you can see from the Java program logging output, the extension class loader is the actual super parent of the system class loader. Our sample Java program was loaded at the system class loader level. Please note that this class loader chain is very simple for this problem case since we did not create child class loaders at this point. This will be covered in future articles.

Recommendations and resolution strategies

Now find below my recommendations and resolution strategies for NoClassDefFoundError problem case 1:

-        Review the java.lang.NoClassDefFoundError error and identify the missing Java class
-        Verify and locate the missing Java class from your compile / build environment
-        Determine if the missing Java class is from your application code, third part API or even the Java EE container itself. Verify where the missing JAR file(s) is / are expected to be found
-        Once found, verify your runtime environment Java classpath for any typo or missing JAR file(s)
-        If the problem is triggered from a Java EE application, perform the same above steps but verify the packaging of your EAR / WAR file for missing JAR and other library file dependencies such as MANIFEST

Please feel free to post any question or comment. The part 3 is now available.

36 comments:

Thanks for this second part P-H. I must say you have covered it nicely especially on Classloader perspective which is major issue on J2EE environment. As I said earlier both your part 1 and this post effectively complement my post 3 ways to solve NoClassDefFoundError in Java J2EE. keep it up.

Javin

omg, i cant resolve this error:
java.lang.NoClassDefFoundError: org/hibernate/transform/ResultTransformer

I'm trying 3 days already but nothing :(.

Hi Haris,

Can you please provide more detail and the actual Exception Stack Trace of your error?

Thanks.
P-H

I also need help.
Here's my error,

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: com/lowagie/text/SplitCharacter
at net.sf.jasperreports.engine.JasperExportManager.exportToPdfFile(JasperExportManager.java:145)
at net.sf.jasperreports.engine.JasperExportManager.exportReportToPdfFile(JasperExportManager.java:497)
at Main.getcashsales(Main.java:509)
at Main.access$2(Main.java:495)
at Main$5.mousePressed(Main.java:185)
at java.awt.AWTEventMulticaster.mousePressed(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$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$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: com.lowagie.text.SplitCharacter
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
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)
... 37 more

I really have no idea how to solve this one. I'm guessing if it compiled, then the class wouldn't be missing. I'm just assuming though. I also tried including the jar file that has the class in the classpath but still nothing.

Hi Ananonymous,

Can you please give detail on your runtime environment and how you are packaging & deploying your application? What Im suspecting is the JAR file (iText.jar i assume) containing this missing class >> com/lowagie/text/SplitCharacter is not deployed to the right class loader.

The default class loader model, parent first, can cause some problem, especially if the JAR file is not deployed at the right place.

Regards,
P-H

Thanks for the immediate response. So, I'm using Eclipse. And there's this JMenuItem that when you click/press on it, it's suppose to generate a pdf file. These are the JAR files i needed for that to function:
* jasperreports-4.7.0.jar
* commons-logging-1.1.1.jar
* commons-digester-2.1.jar
* commons-beanutils-1.8.0.jar
* commons-collections-2.1.1.jar
* commons-javaflow-20060411.jar

So when i call on this,
JasperExportManager.exportReportToPdfFile(print,"reports/shift.pdf");

it generates noClassDefFoundError. I also tried including itextpdf-5.3.2.jar that has the SplitCharacter class in it but still no go.

Hi anonymous,

I found your problem. JasReports depends on iText for the PDF stuff related library. The itextpdf jar you are trying to use is the latest version. They did refactor lot of things so you cannot use this version. You will need to obtain the itext2.1.6. Try this link:
http://olex.openlogic.com/packages/itext/2.1.6

I also recommend that you check with the JasperReports community which version of itext they recommend you to use.

Download and import itext2.1.6.jar to your project and let me know if your problem is resolved.

Thanks.
P-H

Wow. Thanks. It's working now.
Can I just ask which part told you that? My mind is drawing out nothing.

Hi anonymous,

Don`t worry, NoClassDefFoundError is a hard problem which is why I created this article series. This article actually part was describing exactly your problem e.g. missing JAR file.

The missing piece of your analysis was to open the itext5.x version. You would have seen that the class was missing. Then I looked at earlier version of itext and found reference to 2.1.6.

Problem solved!

Thanks for your comments.
Regards,
P-H

Right. I just realized that the location was different. Thanks a bunch.

Hey P-H

Thanks for you article. I did get an insight on what the problem means but am still unable to figure out how to solve it. I have the similar issue and below if my ST

java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.hadoop.hbase.util.Bytes.(Bytes.java:55)
at com.cccccc.flux.test.utility.HBaseTests.(HBaseTests.java:61)
at com.cccccc.landlord.topology.LandlordTopologyTest.testTopology(LandlordTopologyTest.java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:76)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 30 more

Any suggestions? If its a missing JAR how do I find it?


Hi noMad,

I suggest that you read my article part #3 as well. This missing class is part of the Apache commons logging which is referenced by org.apache.hadoop.hbase.util.Bytes. Can you please check your runtime classpath and see if Apache commons logging JAR file is included for the runtime classpath?

Thanks.
P-H

Hello P-H,

About this issue: I generated some custom java objects and I deployed them into a objects.jar file.
With JDeveloper, I generate a new code, let's say "Test.java", and I'm able to invoke, and correctly use, the java classes generated with this code.
Every thing is working running time, I modify the deployment profile of my Test.project and I add under WEB-INF/libs the object.jar file.
Once I deploy I get the error:

Exception in thread "main" java.lang.NoClassDefFoundError: com/objects/MyList
at com.test.main(test.java:7)
Caused by: java.lang.ClassNotFoundException: com.objects.MyList
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 1 more

What should I do in this case?

Thank you in advance,

Robert

Hi, I get such message in Eclipse, while try run my selenium test:

java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at org.junit.internal.builders.SuiteMethodBuilder.hasSuiteMethod(SuiteMethodBuilder.java:20)
at org.junit.internal.builders.SuiteMethodBuilder.runnerForClass(SuiteMethodBuilder.java:13)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.(JUnit4TestReference.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.(JUnit4TestClassReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.WebDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
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)
... 18 more

How to fix this?
Thank you

Hi Robert,

java.lang.NoClassDefFoundError: com/objects/MyList

This error means that you did not include this referencing class to your WebApp class loader. The WebApp classloader did. find your test.java class file and not the referencing class: com/objects/MyList

Can you please confirm how you packaged com/objects/MyList inside your WebApp / WEB-INF?

Thanks.
P-H

Hi anonymous,

java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver

We can see from the Eclipse error that this is triggered from your JUnit test case execution. The problem is that your runtime classpath is missing the referencing library WebDriver; Google web automation tool library.

Please include this WebDriver library in your runtime classpath.

http://code.google.com/p/selenium/wiki/GettingStarted

Thanks.
P-H

Is there any way to simply turn off run time linking and force static linking as in a conventional program, so this problem just doesn't happen?

Hi Anonymous,

Not at this point with current Java specifications. Java classloader is a powerful concept but at the same time has some cons such as facing complex issues like NoClassDefFoundError.

At this point the best you can do is prevent problem to happen as much as you can and improve your classloader knowledge for faster troubleshooting & root cause analysis.

Thanks.
P-H

Hi,
I completely with your concept that prone the avoid of "Java.lang.RuntimeException: Unable to instantiate application com.restoID.RestoIDApp: java.lang.ClassNotFoundException:" than trying to debug it here is the stack of similar error I've been trying to debug unsuccessfully. I will really appreciate If you or someone in this forum can help.
Full stack:

ava.lang.RuntimeException: Unable to instantiate application com.restoID.RestoIDApp: java.lang.ClassNotFoundException:

Hi Toni,

We can see that your application is unable to find a particular class within RestoID. Can you please share the entire stack trace & error from your logs? We need to identify which class is missing from the classpath / class loader tree.

Thanks.
P-H

I have the same kind of class loader issue getting this at my Stack Trace.

Exception in thread "main" java.lang.NoClassDefFoundError: XxservreqSearchQueryHelperTest/java
Caused by: java.lang.ClassNotFoundException: XxservreqSearchQueryHelperTest.java
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: XxservreqSearchQueryHelperTest.java. Program will exit.

Hi Ruchi,

Your program is missing this class from the classpath/classloder:

XxservreqSearchQueryHelperTest.java

Is this a class from your application? Please where this class is located e.g. which JAR file and make sure it is part of your application classpath/classloader.

Regards,
P-H

Hello P-H

would you please take a look at this:

> java -classpath ./CallerClassA.jar;./ReferencingClassA.jar;MainProgram.jar
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-d32 use a 32-bit data model if available
-d64 use a 64-bit data model if available
-server to select the "server" VM
The default VM is server,
because you are running on a server-class machine.


-cp
-classpath
A : separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D=
set a system property
-verbose:[class|gc|jni]
enable verbose output
-version print product version and exit
-version:
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -no-jre-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:...|:]
-enableassertions[:...|:]
enable assertions with specified granularity
-da[:...|:]
-disableassertions[:...|:]
disable assertions with specified granularity
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:[=]
load native agent library , e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:[=]
load native agent library by full pathname
-javaagent:[=]
load Java programming language agent, see java.lang.instrument
-splash:
show splash screen with specified image
See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.
./ReferencingClassA.jar: line 2: package: command not found
./ReferencingClassA.jar: line 6: /bin: Is a directory
./ReferencingClassA.jar: line 7: CallerClassA.jar: command not found
./ReferencingClassA.jar: line 8: CallerClassA.jar: command not found
./ReferencingClassA.jar: line 9: CallerClassA.jar: command not found
./ReferencingClassA.jar: line 10: */: No such file or directory
./ReferencingClassA.jar: line 11: public: command not found
./ReferencingClassA.jar: line 13: syntax error near unexpected token `('
./ReferencingClassA.jar: line 13: ` private final static String CLAZZ = ReferencingClassA.class.getName();'
If 'MainProgram.jar' is not a typo you can use command-not-found to lookup the package that contains it, like this:
cnf MainProgram.jar

It's opensuse 12.2

i've installed java following these steps
http://haulynjason.net/weblog/2011/12/setup-sun-jdk-on-opensuse/

Getting this error after using new slf4j jars that I have kept in classpath properly :
java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory...
What shopuld I do now??

I just wanted to mention that I encountered the NoClassDefFoundError on a project I was working on. The server being setup was using a different version of Java by IBM, rather than Oracle's. On my development machine it worked for me, but on the server I got that error. The issue was resolved once they redid Java using Oracle's version (and Tomcat as well). This may be the solution to someone's problem here as well to consider.

Hi I am having similar error:
java.lang.NoClassDefFoundError: Could not initialize class org.jfree.chart.JFreeChart
at org.jfree.chart.ChartFactory.createLineChart(ChartFactory.java:1242)
at var.DatabaseLevelReport.doGet(Unknown Source)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:288)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:263)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1018)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:196)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)

i am not able to figure anythign out. any help would be appreciated.

Hi anonymous,

You are likely missing a JAR file in your runtime classpath from JFreeChart. Please check your runtime classpath and make sure you included the proper JFreeChart libraries/JAR files.

Regards,
P-H

I have change 'open with ' setting of java class file ,now I 'm getting the error "Exception in thread "main" java.lang.NoClassDefFoundError: case1"
& my class file is also at proper location ,still I m getting this error ,

Hi, check for the location of case1 class. It looks like that you wrongly configured your runtime classpath from your Java IDE.

Regards,
P-H

As you have suggested i check my settings of case1 classpath but still ,
i m getting the error like,

C:\Program Files (x86)\Java\jdk1.7.0_11>java case1
Exception in thread "main" java.lang.NoClassDefFoundError: case1
Caused by: java.lang.ClassNotFoundException: case1
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: case1. Program will exit.

& also the icon of java class file shows symbol of cmd...
i think that's y the cmd is not able to find the classfile of "case1" ?
Now ,i can't understand how to solve this?
I have uninstall all previous jdk & now i reinstall it then also the symbol of java class file is remain as it is(cmd).

Hi, Please help me to fix this issue
C:\Jars>javac -cp "C:\Program Files\Java\selenium\*.jar";"OneReports.jar";"testn
g.jar" test\TestngTestSuiteUsingXML.java

C:\Jars>java -cp "C:\Program Files\Java\selenium\*.jar";"OneReports.jar";"testng
.jar" test.TestngTestSuiteUsingXML
[[TestNGClassFinder]] Unable to read methods on class test.LoginOneReports - una
ble to resolve class reference org/openqa/selenium/WebDriver
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/W
ebDriver
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetPublicMethods(Unknown Source)
at java.lang.Class.getMethods(Unknown Source)
at org.testng.internal.TestNGClassFinder.(TestNGClassFinder.java:5
9)
at org.testng.TestRunner.initMethods(TestRunner.java:409)
at org.testng.TestRunner.init(TestRunner.java:235)
at org.testng.TestRunner.init(TestRunner.java:205)
at org.testng.TestRunner.(TestRunner.java:153)
at org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner(SuiteRu
nner.java:522)
at org.testng.SuiteRunner.init(SuiteRunner.java:157)
at org.testng.SuiteRunner.(SuiteRunner.java:111)
at org.testng.TestNG.createSuiteRunner(TestNG.java:1299)
at org.testng.TestNG.createSuiteRunners(TestNG.java:1286)
at org.testng.TestNG.createSuiteRunners(TestNG.java:1289)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.run(TestNG.java:1057)
at test.TestngTestSuiteUsingXML.main(TestngTestSuiteUsingXML.java:20)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.WebDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
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)
... 18 more

C:\Jars>

Hi,

The problem is with your classpath definition, you have to specify each JAR file by itself, remove the *.jar, add each JAR from Selenium individually.

Thx
P-H

hi..

i have checked out the project from svn..its is giving problem in tomcat saying
FileNotFoundException gsapp.properties
i had set the path of gsapp file but still the same error..

and the project i have checked out giving dependencies error..

Hi Please Help me to fix This issue
I have This Error That i don't know how to solve,I Don't Know What is Wrong,
Pretty Please Help,.

(My Ireport) C:\Program Files\Java\jre7\iReport-5.5.0


Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at net.sf.jasperreports.engine.util.JRLoader.(JRLoader.java:68)
at net.sf.jasperreports.engine.JRPropertiesUtil.loadProperties(JRPropertiesUtil.java:99)
at net.sf.jasperreports.engine.DefaultJasperReportsContext.initProperties(DefaultJasperReportsContext.java:94)
at net.sf.jasperreports.engine.DefaultJasperReportsContext.(DefaultJasperReportsContext.java:71)
at net.sf.jasperreports.engine.DefaultJasperReportsContext.(DefaultJasperReportsContext.java:59)
at net.sf.jasperreports.engine.JasperCompileManager.getDefaultInstance(JasperCompileManager.java:84)
at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:459)
at Report.bReportActionPerformed(Report.java:110)
at Report.access$000(Report.java:12)
at Report$2.actionPerformed(Report.java:83)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3320)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
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)

Hi I have a problema
java.lang.ClassNotFoundException: com.sun.pdfview.PDFFile ------------------------- Loader Info ------------------------- ClassLoader name: [sap.com/internos] Loader hash code: 587dd2bd Living status: alive Direct parent loaders: [system:Frame] [interface:webservices] [interface:cross] [interface:security] [interface:transactionext] [library:webservices_lib] [library:opensql] [library:jms] [library:ejb20] [service:p4] [service:ejb] [service:servlet_jsp] [library:tc~ddic~runtime~facade] [library:tc~bl~logging~api] [library:tc~bl~exception~lib] [sap.com/tc~wd~api] [library:tc~cm~arfc2~api] Resources: D:\usr\sap\CPD\J00\j2ee\cluster\apps\sap.com\internos\servlet_jsp\webdynpro\resources\sap.com\internos\root\WEB-INF\lib\sap.com~internos.jar ---------------------------------------------------------------

I am Using PDFRenderer-0.9.1.jar on webdynpro as java 7.3

Post a Comment