Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Exception in thread "main" java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing"

Tags:

java

junit

On my Ubuntu, I run an java executable, with error about some package I didn't explicitly use in my code. What might be the solution? Thanks.

$ java -cp .:/home/tim/program_files/programming/java/junit-4.11.jar MyTest
Exception in thread "main" java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
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)
at org.junit.runner.Computer.getSuite(Computer.java:28)
at org.junit.runner.Request.classes(Request.java:75)
at org.junit.runner.JUnitCore.run(JUnitCore.java:128)
at org.junit.runner.JUnitCore.runClasses(JUnitCore.java:73)
at MyTest.main(MyTest.java:13)
Caused by: java.lang.ClassNotFoundException: org.hamcrest.SelfDescribing
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)
... 17 more
like image 721
Tim Avatar asked Oct 07 '14 23:10

Tim


1 Answers

From Junit Wiki

Plain-old JAR
Download the following JARs and put them on your test classpath:

junit.jar hamcrest-core.jar

Add the hamcrest core jar to the class path to resolve the issue.

like image 76
Ajay George Avatar answered Nov 15 '22 03:11

Ajay George