Why am I getting a NoClassDefFoundError in Java?
Asked Answered
C

32

671

I am getting a NoClassDefFoundError when I run my Java application. What is typically the cause of this?

Cuvette answered 29/8, 2008 at 14:59 Comment(1)
I believe it can also happen if you don't run your java program with the correct syntax. For instance, you have to call your class from the root bin folder with the full package name (ie. my.package.myClass). I'd be more specific if I could but I'm not much of a java guy. I just remember messing this up a few times.Outride
A
308

This is caused when there is a class file that your code depends on and it is present at compile time but not found at runtime. Look for differences in your build time and runtime classpaths.

Astred answered 29/8, 2008 at 15:1 Comment(9)
I had this error happen when putting a source file under the wrong namespace/package. I figured I could just put it anywhere, and the compiler was happy. Turns out I should have been more diligent for runtime to be happy as well.Yost
I had this error once when my server ran out of memory during a file upload. Every time I tried the upload, I'd get a different error. Eventually it told me I didn't have enough heap space.Variform
This answer is not necessarily true and will be misleading to many people! See the better answer from Jared below.Lidstone
I ran mvn -X clean compiler package 2>&1 >test.log so I could see the gory details before the NoClassDefFound error report.Keelson
@DaveL. Thanks! Jared's answer with 400+ upvotes is way below! One answer with -4 up(down?)votes is way above it. There is something fishy about SO's answer ordering logic.Taciturnity
This is a long-shot for someone, but I encountered this error because the class in question contained a SimpleDateFormat that was initialized with an invalid character (I had T in the middle instead of 'T').Traction
Oddly enough I just re-compiled my file, and that seemed to clear things up. I must have altered something since the initial compilationFlare
The class name (NoClassDefFoundError) means the class file is found and loaded but cannot be converted to a JVM class definition, it is possibly broken by any uncaught exception within static initializer or placed at different place from the one its namespace implies (sub-path in a jar or folder, wrong file name case).Heyman
In regards to this answer, the question is how? As someone who is new to Java, I understand what the answer says but I have no idea how to check for the differences between build and runtime class paths.Cooper
A
1043

While it's possible that this is due to a classpath mismatch between compile-time and run-time, it's not necessarily true.

It is important to keep two or three different exceptions straight in our head in this case:

  1. java.lang.ClassNotFoundException This exception indicates that the class was not found on the classpath. This indicates that we were trying to load the class definition, and the class did not exist on the classpath.

  2. java.lang.NoClassDefFoundError This exception indicates that the JVM looked in its internal class definition data structure for the definition of a class and did not find it. This is different than saying that it could not be loaded from the classpath. Usually this indicates that we previously attempted to load a class from the classpath, but it failed for some reason - now we're trying to use the class again (and thus need to load it, since it failed last time), but we're not even going to try to load it, because we failed loading it earlier (and reasonably suspect that we would fail again). The earlier failure could be a ClassNotFoundException or an ExceptionInInitializerError (indicating a failure in the static initialization block) or any number of other problems. The point is, a NoClassDefFoundError is not necessarily a classpath problem.

Astrosphere answered 22/4, 2011 at 15:28 Comment(12)
Thanks for mentioning the cause of a NoClassDefFoundError, this helped me a lot! In my case an ExceptionInInitializerError was thrown before, that's how I found out about errors in static blocks.Crean
@Jared, When I am getting Error: Could not find or load main class, it will be classified under which category of error?Bellflower
@Pops: Made the language more verbose to specify the objects of the verbs "try" :)Astrosphere
ClassCircularityError and ClassFormatError may also occur during the loading process: docs.oracle.com/javase/specs/jls/se5.0/html/…Girder
@Bellflower the "could not find or load main class" is not a Java exception, it is caused by the launcher (which inspects the JAR and the main manifest attribute).Coryden
Im getting this issue too trying to run a junit test. how do i check compiletime vs runtime classpath?Lessor
I ran mvn -X clean compiler package 2>&1 >test.log so I could see the gory details before the NoClassDefFound error report. It did indicate that it was caused by a previous ClassNotFound exception for a class I had thought I wasn't using anymore.Keelson
ClassNotFoundException is also thrown when a class has static initialization that throws an error or exception. They probably should have picked a different name for that event.Yahoo
Can someone please help me in understanding a statement in this answer The earlier failure could be a ClassNotFoundException or an ExceptionInInitializerError (indicating a failure in the static initialization block). Can previous possible error be 'ClassNotFoundException', because previous error has to be thrown while loading class like in static block. And static block doesn't allow to throw checked exception.Intercollegiate
@VipulGoyal: I've been out of Java in my daily life for a while now. As I remember, a ClassNotFoundException ALWAYS has another root cause the first time it's thrown in a given JVM invocation, and that root cause is included as the cause of the exception. Subsequent attempts to load the class may immediately throw a ClassNotFoundException if the JVM has reason to believe nothing has changed, and it still won't load. Someone will correct me if my memory is faded ;)Astrosphere
If I get a NoClassDefFoundError how could "The earlier failure be a ClassNotFoundException"? What does it mean when I only get "NoClassDefFoundErrors"?Indaba
Thanks. I faced the 2nd error in CloudFoundry and restarting the application resolved the issue for mePaquin
A
308

This is caused when there is a class file that your code depends on and it is present at compile time but not found at runtime. Look for differences in your build time and runtime classpaths.

Astred answered 29/8, 2008 at 15:1 Comment(9)
I had this error happen when putting a source file under the wrong namespace/package. I figured I could just put it anywhere, and the compiler was happy. Turns out I should have been more diligent for runtime to be happy as well.Yost
I had this error once when my server ran out of memory during a file upload. Every time I tried the upload, I'd get a different error. Eventually it told me I didn't have enough heap space.Variform
This answer is not necessarily true and will be misleading to many people! See the better answer from Jared below.Lidstone
I ran mvn -X clean compiler package 2>&1 >test.log so I could see the gory details before the NoClassDefFound error report.Keelson
@DaveL. Thanks! Jared's answer with 400+ upvotes is way below! One answer with -4 up(down?)votes is way above it. There is something fishy about SO's answer ordering logic.Taciturnity
This is a long-shot for someone, but I encountered this error because the class in question contained a SimpleDateFormat that was initialized with an invalid character (I had T in the middle instead of 'T').Traction
Oddly enough I just re-compiled my file, and that seemed to clear things up. I must have altered something since the initial compilationFlare
The class name (NoClassDefFoundError) means the class file is found and loaded but cannot be converted to a JVM class definition, it is possibly broken by any uncaught exception within static initializer or placed at different place from the one its namespace implies (sub-path in a jar or folder, wrong file name case).Heyman
In regards to this answer, the question is how? As someone who is new to Java, I understand what the answer says but I have no idea how to check for the differences between build and runtime class paths.Cooper
R
157

Here is the code to illustrate java.lang.NoClassDefFoundError. Please see Jared's answer for detailed explanation.

NoClassDefFoundErrorDemo.java

public class NoClassDefFoundErrorDemo {
    public static void main(String[] args) {
        try {
            // The following line would throw ExceptionInInitializerError
            SimpleCalculator calculator1 = new SimpleCalculator();
        } catch (Throwable t) {
            System.out.println(t);
        }
        // The following line would cause NoClassDefFoundError
        SimpleCalculator calculator2 = new SimpleCalculator();
    }

}

SimpleCalculator.java

public class SimpleCalculator {
    static int undefined = 1 / 0;
}
Respirator answered 13/2, 2015 at 19:20 Comment(3)
And the reason is that after first try jvm already knows its not going to work and throw different exception second time?Alkylation
@Alkylation Apparently it has stored somewhere the unsuccessful class initialisation of SimpleCalculator after the divide by zero? Does someone have a reference to the official documentation for this behaviour?Deliberation
@PhilipRego Not sure what you mean by a 'pure' NoClassDefFoundError. The first time new SimpleCalculator() is called, you get an ExceptionInInitializerError with a caused by of ArithmeticException. The second time you call new SimpleCalculator() you get a NoClassDefFoundError as pure as any other. The point is you can get a NoClassDefFoundError for a reason other than SimpleCalculator.class not being on the classpath at runtime.Composer
G
51

NoClassDefFoundError In Java

Definition:

  1. Java Virtual Machine is not able to find a particular class at runtime which was available at compile time.

  2. If a class was present during compile time but not available in java classpath during runtime.

enter image description here

Examples:

  1. The class is not in Classpath, there is no sure shot way of knowing it but many times you can just have a look to print System.getproperty("java.classpath") and it will print the classpath from there you can at least get an idea of your actual runtime classpath.
  2. A simple example of NoClassDefFoundError is class belongs to a missing JAR file or JAR was not added into classpath or sometimes jar's name has been changed by someone like in my case one of my colleagues has changed tibco.jar into tibco_v3.jar and the program is failing with java.lang.NoClassDefFoundError and I were wondering what's wrong.

  3. Just try to run with explicitly -classpath option with the classpath you think will work and if it's working then it's a sure short sign that someone is overriding java classpath.

  4. Permission issue on JAR file can also cause NoClassDefFoundError in Java.
  5. Typo on XML Configuration can also cause NoClassDefFoundError in Java.
  6. when your compiled class which is defined in a package, doesn’t present in the same package while loading like in the case of JApplet it will throw NoClassDefFoundError in Java.

Possible Solutions:

  1. The class is not available in Java Classpath.
  2. If you are working in J2EE environment than the visibility of Class among multiple Classloader can also cause java.lang.NoClassDefFoundError, see examples and scenario section for detailed discussion.
  3. Check for java.lang.ExceptionInInitializerError in your log file. NoClassDefFoundError due to the failure of static initialization is quite common.
  4. Because NoClassDefFoundError is a subclass of java.lang.LinkageError it can also come if one of it dependency like native library may not available.
  5. Any start-up script is overriding Classpath environment variable.
  6. You might be running your program using jar command and class was not defined in manifest file's ClassPath attribute.

Resources:

3 ways to solve NoClassDefFoundError

java.lang.NoClassDefFoundError Problem patterns

Glochidium answered 10/8, 2016 at 17:16 Comment(3)
Great answer. I think I've tried everything you suggest and still have that problem. I can exclude some of these due to the jar working with spring, but seems to not be liked by java.sql (in my case the sap db driver for Hana).Hexad
Its actually called System.getproperty("java.class.path")Hamforrd
Issue is still not resolved but it is very useful info.Night
R
34

I have found that sometimes I get a NoClassDefFound error when code is compiled with an incompatible version of the class found at runtime. The specific instance I recall is with the apache axis library. There were actually 2 versions on my runtime classpath and it was picking up the out of date and incompatible version and not the correct one, causing a NoClassDefFound error. This was in a command line app where I was using a command similar to this.

set classpath=%classpath%;axis.jar

I was able to get it to pick up the proper version by using:

set classpath=axis.jar;%classpath%;
Ruffled answered 29/8, 2008 at 15:6 Comment(2)
Had the same issue. Turns out I compiled the war file with Java7, but my Tomcat installation was using Java6. I had to update my environmental variablesTannate
If this happens like that then i'll say Java is in a mess. +2 if this is true. Can't verify this yet. If found true will do+1 again (In comments)Assuan
M
10

One interesting case in which you might see a lot of NoClassDefFoundErrors is when you:

  1. throw a RuntimeException in the static block of your class Example
  2. Intercept it (or if it just doesn't matter like it is thrown in a test case)
  3. Try to create an instance of this class Example

static class Example {
    static {
        thisThrowsRuntimeException();
    }
}

static class OuterClazz {

    OuterClazz() {
        try {
            new Example();
        } catch (Throwable ignored) { //simulating catching RuntimeException from static block
            // DO NOT DO THIS IN PRODUCTION CODE, THIS IS JUST AN EXAMPLE in StackOverflow
        }

        new Example(); //this throws NoClassDefFoundError
    }
}

NoClassDefError will be thrown accompanied with ExceptionInInitializerError from the static block RuntimeException.


This is especially important case when you see NoClassDefFoundErrors in your UNIT TESTS.

In a way you're "sharing" the static block execution between tests, but the initial ExceptionInInitializerError will be just in one test case. The first one that uses the problematic Example class. Other test cases that use the Example class will just throw NoClassDefFoundErrors.

Mariettamariette answered 4/12, 2018 at 16:4 Comment(1)
This is pretty damn useful piece of advice in real life. I just had the same situation with class attribute initializers. You only have once chance to see the actual problem in the log. Once the class is loaded (or attempted anyway) you need to restart everything.Atone
K
9

This is the best solution I found so far.

Suppose we have a package called org.mypackage containing the classes:

  • HelloWorld (main class)
  • SupportClass
  • UtilClass

and the files defining this package are stored physically under the directory D:\myprogram (on Windows) or /home/user/myprogram (on Linux).

The file structure will look like this: enter image description here

When we invoke Java, we specify the name of the application to run: org.mypackage.HelloWorld. However we must also tell Java where to look for the files and directories defining our package. So to launch the program, we have to use the following command: enter image description here

Kucik answered 15/9, 2015 at 18:44 Comment(0)
I
6

I was using Spring Framework with Maven and solved this error in my project.

There was a runtime error in the class. I was reading a property as integer, but when it read the value from the property file, its value was double.

Spring did not give me a full stack trace of on which line the runtime failed. It simply said NoClassDefFoundError. But when I executed it as a native Java application (taking it out of MVC), it gave ExceptionInInitializerError which was the true cause and which is how I traced the error.

@xli's answer gave me insight into what may be wrong in my code.

Impearl answered 10/8, 2015 at 8:16 Comment(1)
Same thing happened to me when programming a Servlet (NoClassDefFoundError was actually caused by ExceptionInInitalizerError, which was caused by DateTimeParseException). It's a bit misleading, isn't it? I know they probably had their reasons to make it like that, but it would be so nice to have at least a small hint, that NoClassDefFoundError was a result of another exception, without the need to deduce it. Just throwing ExceptionInInitializerError again would be much more clear. Sometimes the connection between the two may not be that obvious.Bose
S
5

I get NoClassFoundError when classes loaded by the runtime class loader cannot access classes already loaded by the java rootloader. Because the different class loaders are in different security domains (according to java) the jvm won't allow classes already loaded by the rootloader to be resolved in the runtime loader address space.

Run your program with 'java -javaagent:tracer.jar [YOUR java ARGS]'

It produces output showing the loaded class, and the loader env that loaded the class. It's very helpful tracing why a class cannot be resolved.

// ClassLoaderTracer.java
// From: https://blogs.oracle.com/sundararajan/entry/tracing_class_loading_1_5

import java.lang.instrument.*;
import java.security.*;

// manifest.mf
// Premain-Class: ClassLoadTracer

// jar -cvfm tracer.jar manifest.mf ClassLoaderTracer.class

// java -javaagent:tracer.jar  [...]

public class ClassLoadTracer 
{
    public static void premain(String agentArgs, Instrumentation inst) 
    {
        final java.io.PrintStream out = System.out;
        inst.addTransformer(new ClassFileTransformer() {
            public byte[] transform(ClassLoader loader, String className, Class classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {

                String pd = (null == protectionDomain) ? "null" : protectionDomain.getCodeSource().toString();
                out.println(className + " loaded by " + loader + " at " + new java.util.Date() + " in " + pd);

                // dump stack trace of the thread loading class 
                Thread.dumpStack();

                // we just want the original .class bytes to be loaded!
                // we are not instrumenting it...
                return null;
            }
        });
    }
}
Stevenage answered 9/9, 2015 at 12:2 Comment(1)
Link is dead. Try the archived version: web.archive.org/web/20131216000019/https://blogs.oracle.com/…Historicism
T
4

The technique below helped me many times:

System.out.println(TheNoDefFoundClass.class.getProtectionDomain().getCodeSource().getLocation());

where the TheNoDefFoundClass is the class that might be "lost" due to a preference for an older version of the same library used by your program. This most frequently happens with the cases, when the client software is being deployed into a dominant container, armed with its own classloaders and tons of ancient versions of most popular libs.

Toner answered 27/7, 2016 at 13:44 Comment(0)
N
4

Java ClassNotFoundException vs NoClassDefFoundError

[ClassLoader]

Static vs Dynamic class loading

Static(Implicit) class loading - result of reference, instantiation, or inheritance.

MyClass myClass = new MyClass();

Dynamic(Explicit) class loading is result of Class.forName(), loadClass(), findSystemClass()

MyClass myClass = (MyClass) Class.forName("MyClass").newInstance();

Every class has a ClassLoader which uses loadClass(String name); that is why

explicit class loader uses implicit class loader

NoClassDefFoundError is a part of explicit class loader. It is Error to guarantee that during compilation this class was presented but now (in run time) it is absent.

ClassNotFoundException is a part of implicit class loader. It is Exception to be elastic with scenarios where additionally it can be used - for example reflection.

Neona answered 26/3, 2021 at 11:25 Comment(0)
U
3

In case you have generated-code (EMF, etc.) there can be too many static initialisers which consume all stack space.

See Stack Overflow question How to increase the Java stack size?.

Unofficial answered 7/11, 2016 at 14:3 Comment(2)
"EMF"? Do you mean "MEF"?Quaff
Nope. EMf as Eclipse Modeling Framework. In automotive we may face this error when running generated code.Unofficial
H
1

Two different checkout copies of the same project

In my case, the problem was Eclipse's inability to differentiate between two different copies of the same project. I have one locked on trunk (SVN version control) and the other one working in one branch at a time. I tried out one change in the working copy as a JUnit test case, which included extracting a private inner class to be a public class on its own and while it was working, I open the other copy of the project to look around at some other part of the code that needed changes. At some point, the NoClassDefFoundError popped up complaining that the private inner class was not there; double-clicking in the stack trace brought me to the source file in the wrong project copy.

Closing the trunk copy of the project and running the test case again got rid of the problem.

Helbonna answered 25/10, 2017 at 6:58 Comment(0)
M
1

I fixed my problem by disabling the preDexLibraries for all modules:

dexOptions {
        preDexLibraries false
        ...
Muimuir answered 5/2, 2018 at 2:34 Comment(0)
M
1

NoClassDefFoundError can also occur when a static initializer tries to load a resource bundle that is not available in runtime, for example a properties file that the affected class tries to load from the META-INF directory, but isn’t there. If you don’t catch NoClassDefFoundError, sometimes you won’t be able to see the full stack trace; to overcome this you can temporarily use a catch clause for Throwable:

try {
    // Statement(s) that cause(s) the affected class to be loaded
} catch (Throwable t) {
    Logger.getLogger("<logger-name>").info("Loading my class went wrong", t);
}
Maunsell answered 27/9, 2018 at 20:30 Comment(5)
This is incorrect. A missing resource won't give you this error. You will only get it if a class is missing.Galah
@StephenC Maybe I should emphasize that part more, but I wrote for example a properties file that the affected class tries to load from the META-INF directory. This has actually happened to me and I was able to resolve the NoClassDefFoundError by adding the missing properties file. I added this answer exactly because one wouldn’t expect this error under the mentioned circumstances.Deliberation
You have missed something very important in your explanation then, because the only way that a missing resource file could trigger that exception is if you are attempting to load the resource file in a static initialization ... which triggered an unchecked exception and caused the class init to fail. Any unchecked exception propagating from static initialization would do that.Galah
If I am wrong (i.e. this is not due to failed static initialization), I would be interested to see an actual example (i.e. an MCVE) that demonstrates the behavior.Galah
@StephenC You’re absolutely right, though :( I looked up the case where I encountered this issue and it indeed involved a static initializer trying to load a resource bundle. I shall augment/correct my description of the cause. Thanks for pointing this out.Deliberation
M
1

I got this error when I add Maven dependency of another module to my project, the issue was finally solved by add -Xss2m to my program's JVM option(It's one megabyte by default since JDK5.0). It's believed the program does not have enough stack to load class.

Misesteem answered 1/11, 2019 at 4:48 Comment(0)
H
1

In my case I was getting this error due to a mismatch in the JDK versions. When I tried to run the application from Intelij it wasn't working but then running it from the command line worked. This is because Intelij was attempting to run it with the Java 11 JDK that was setup but on the command line it was running with the Java 8 JDK. After switching that setting under File > Project Structure > Project Settings > Project SDK, it worked for me.

Hebron answered 24/2, 2020 at 20:30 Comment(0)
M
1

Update [https://www.infoq.com/articles/single-file-execution-java11/]:

In Java SE 11, you get the option to launch a single source code file directly, without intermediate compilation. Just for your convenience, so that newbies like you don't have to run javac + java (of course, leaving them confused why that is).

Murphy answered 15/8, 2020 at 15:11 Comment(0)
M
1

I was getting NoClassDefFoundError while trying to deploy application on Tomcat/JBOSS servers. I played with different dependencies to resolve the issue, but kept getting the same error. Marked all javax.* dependencies as provided in pom.xml, And war literally had no Dependency in it. Still the issue kept popping up.

Finally realized that src/main/webapps/WEB-INF/classes had classes folder which was getting copied into my war, so instead of compiled classes, this classes were getting copied, hence no dependency change was resolving the issue.

Hence be careful if any previously compiled data is getting copied, After deleting classes folder and fresh compilation, It worked!..

Matronly answered 18/3, 2021 at 12:47 Comment(0)
L
0

If someone comes here because of java.lang.NoClassDefFoundError: org/apache/log4j/Logger error, in my case it was produced because I used log4j 2 (but I didn't add all the files that come with it), and some dependency library used log4j 1. The solution was to add the Log4j 1.x bridge: the jar log4j-1.2-api-<version>.jar which comes with log4j 2. More info in the log4j 2 migration.

Lychnis answered 19/6, 2017 at 13:48 Comment(0)
M
0

This error can be caused by unchecked Java version requirements.

In my case I was able to resolve this error, while building a high-profile open-source project, by switching from Java 9 to Java 8 using SDKMAN!.

sdk list java
sdk install java 8u152-zulu
sdk use java 8u152-zulu

Then doing a clean install as described below.


When using Maven as your build tool, it is sometimes helpful -- and usually gratifying, to do a clean 'install' build with testing disabled.

mvn clean install -DskipTests

Now that everything has been built and installed, you can go ahead and run the tests.

mvn test
Montmartre answered 1/4, 2018 at 19:9 Comment(0)
P
0

I got NoClassDefFound errors when I didn't export a class on the "Order and Export" tab in the Java Build Path of my project. Make sure to put a checkmark in the "Order and Export" tab of any dependencies you add to the project's build path. See Eclipse warning: XXXXXXXXXXX.jar will not be exported or published. Runtime ClassNotFoundExceptions may result.

Permafrost answered 3/4, 2019 at 21:58 Comment(0)
O
0

It could also be because you copy the code file from an IDE with a certain package name and you want to try to run it using terminal. You will have to remove the package name from the code first. This happens to me.

Odoriferous answered 6/8, 2019 at 15:35 Comment(0)
K
0

Everyone talks here about some Java configuration stuff, JVM problems etc., in my case the error was not related to these topics at all and had a very trivial and easy to solve reason: I had a wrong annotation at my endpoint in my Controller (Spring Boot application).

Kinescope answered 29/2, 2020 at 17:7 Comment(0)
T
0

I have had an interesting issue wiht NoClassDefFoundError in JavaEE working with Liberty server. I was using IMS resource adapters and my server.xml had already resource adapter for imsudbJXA.rar. When I added new adapter for imsudbXA.rar, I would start getting this error for instance objects for DLIException, IMSConnectionSpec or SQLInteractionSpec. I could not figure why but I resolved it by creating new server.xml for my work using only imsudbXA.rar. I am sure using multiple resource adapters in server.xml is fine, I just had no time to look into that.

Tribute answered 15/5, 2020 at 17:42 Comment(0)
P
0

I had this error but could not figure out the solution based on this thread but solved it myself.

For my problem I was compiling this code:

package valentines;

import java.math.BigInteger;
import java.util.ArrayList;

public class StudentSolver {
    public static ArrayList<Boolean> solve(ArrayList<ArrayList<BigInteger>> problems) {
        //DOING WORK HERE
        
    }
    public static void main(String[] args){
        //TESTING SOLVE FUNCTION
    }
    
}

I was then compiling this code in a folder structure that was like /ProjectName/valentines Compiling it worked fine but trying to execute: java StudentSolver

I was getting the NoClassDefError.

To fix this I simply removed: package valentines;

I'm not very well versed in java packages and such but this how I fixed my error so sorry if this was already answered by someone else but I couldn't interpret it to my problem.

Palaeontography answered 30/9, 2020 at 0:50 Comment(0)
L
0

My solution to this was to "avail" the classpath contents for the specific classes that were missing. In my case, I had 2 dependencies, and though I was able to compile successfully using javac ..., I was not able to run the resulting class file using java ..., because a Dynamic class in the BouncyCastle jar could not be loaded at runtime.

javac --classpath "ext/commons-io-2.11.0;ext/bc-fips-1.0.2.3" hello.java

So at compile time and by runtime, the JVM is aware of where to fetch Apache Commons and BouncyCastle dependencies, however, when running this, I got

Error: Unable to initialize main class hello
Caused by: java.lang.NoClassDefFoundError: 
org/bouncycastle/jcajce/provider/BouncyCastleFipsProvider

And I therefore manually created a new folder named ext at the same location, as per the classpath, where I then placed the BouncyCastle jar to ensure it would be found at runtime. You can place the jar relative to the class file or the jar file as long as the resulting manifest has the location of the jar specified. Note I only need to avail the one jar containing the missing class file.

Leonardaleonardi answered 21/11, 2022 at 14:15 Comment(0)
Y
0

For me, the issue was due to incorrect dependencies added in pom. To check if that's your issue, run mvn clean verify and it should flag this.

Yakut answered 9/11, 2023 at 12:38 Comment(0)
S
-1

I had the same problem, and I was stock for many hours.

I found the solution. In my case, there was the static method defined due to that. The JVM can not create the another object of that class.

For example,

private static HttpHost proxy = new HttpHost(proxyHost, Integer.valueOf(proxyPort), "http");
Shastashastra answered 14/7, 2016 at 19:46 Comment(0)
M
-1

Java was unable to find the class A in runtime. Class A was in maven project ArtClient from a different workspace. So I imported ArtClient to my Eclipse project. Two of my projects was using ArtClient as dependency. I changed library reference to project reference for these ones (Build Path -> Configure Build Path).

And the problem gone away.

Moramorabito answered 29/11, 2017 at 12:51 Comment(0)
H
-6

I got this message after removing two files from the SRC library, and when I brought them back I kept seeing this error message.

My solution was: Restart Eclipse. Since then I haven't seen this message again :-)

Hospitium answered 14/10, 2015 at 10:19 Comment(1)
That's explained by the most voted answer, when you first compiled, the files were there, then you removed some files, the classes were deleted, so at runtime, you got the ClassNotFound, then you broght them back, but still Eclipse didn't notice so the generated classes were still missing, but after you restarted Eclipse, the workspace was refreshed and the classes were again available, but in general this is not a solution or workaround, the solution is finding which class/jar is missing in the runtime classpath.Lederhosen
L
-8

Make sure this matches in the module:app and module:lib:

android {
    compileSdkVersion 23
    buildToolsVersion '22.0.1'
    packagingOptions {
    }

    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 23
        versionCode 11
        versionName "2.1"
    }
Langelo answered 26/4, 2016 at 16:40 Comment(2)
How your solution is in any way relevant to this common problem?Herder
The sample configuration is not balanced (three {s and two }). Can you fix it?Quaff

© 2022 - 2024 — McMap. All rights reserved.