java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing in Intellij

57,187

Solution 1

Did you include the hamcrest-core-1.3.jar file in your classpath? If not included means include that jar and try once again.

Solution 2

add junit.jar to your project dependence. you may also need to add hamcrest.jar in addition.

Open File->Project Structure,Click Modules->Dependences,add junit.jar.

Solution 3

Latest version of hamcrest-all is available at: https://search.maven.org/search?q=a:hamcrest-all

Download this version (as opposed to the hamcrest-core) and that should do it.

Solution 4

If you come across this (and a few other threads) on this error and adding the jar to dependencies doesn't work, you will need to add to the general java classpath.

I encountered this error in OSX where maven would download the dependency, but not find it when in fork mode.

Adding all the hamcrest jars to Library/Java/Extensions finally fixed the problem when nothing else would.

Share:
57,187
jackyesind
Author by

jackyesind

Updated on December 02, 2020

Comments

  • jackyesind
    jackyesind over 3 years

    I used Intellij Idea 12 Community edition. I am trying to create test case for my class by creating test case. When i run my test case it says

    java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
        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)
        at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:10)
        at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
        at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
        at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
        at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)
        at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:44)
        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.hamcrest.SelfDescribing
        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)
        ... 25 more
    

    How would i run test case in Intellij. I included the junit4.11 jar file to my module

  • th3morg
    th3morg over 9 years
    Upvoted because I needed to add hamcrest in this way, but you go me there :)
  • Isaac
    Isaac almost 8 years
    This worked for me as well, I don't know why adding the Maven dependencies wouldn't though.
  • Darshit Patel
    Darshit Patel almost 3 years
    This worked, but not sure why hamcrest-core.jar doesn't