“线程中的异常”主“java.lang.NoClassDefFoundError:org / hamcrest / SelfDescribing”

时间:2014-10-07 23:02:11

标签: java junit

在我的Ubuntu上,我运行了一个java可执行文件,其中包含一些我在代码中没有明确使用的包的错误。可能是什么解决方案?感谢。

$ 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

1 个答案:

答案 0 :(得分:26)

来自Junit Wiki

  

普通的JAR
  下载以下JAR并将它们放在测试类路径中:

     

junit.jar hamcrest-core.jar

hamcrest核心jar添加到类路径以解决问题。