我使用 Eclipse 创建了一个 Junit 测试用例,它运行良好。我正在尝试使用命令行编译它,但似乎无法做到。
我能够很好地“编译”它..但是现在当我尝试运行它时,我收到以下错误:
JUnit version 4.8.2
Exception in thread "main" java.lang.NoClassDefFoundError: org/hamcrest/SelfDesc
ribing
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
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)
at org.junit.runner.Computer.getSuite(Computer.java:26)
at org.junit.runner.Request.classes(Request.java:69)
at org.junit.runner.JUnitCore.run(JUnitCore.java:117)
at org.junit.runner.JUnitCore.runMain(JUnitCore.java:98)
at org.junit.runner.JUnitCore.runMainAndExit(JUnitCore.java:53)
at org.junit.runner.JUnitCore.main(JUnitCore.java:45)
Caused by: java.lang.ClassNotFoundException: org.hamcrest.SelfDescribing
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
要运行它,我正在使用:
java -cp "E:/Android ADT/adt-bundle-windows-x86_64-20130219/eclipse/plugins/org.junit_4.8.2.v4_8_2_v20110321-1705/junit.jar;." org.junit.runner.JUnitCore SchedulerTest
编译工作正常,编译我使用:
javac -cp "E:/Android ADT/adt-bundle-windows
-x86_64-20130219/eclipse/plugins/org.junit_4.8.2.v4_8_2_v20110321-1705/junit.jar
;." SchedulerTest.java