Could not find or load main class org.junit.runner.JUnitCore

ε祈祈猫儿з 提交于 2019-12-07 02:35:37

问题


I packed test classes into JAR. I have junit-4.10.jar and aJar.jar in the same folder. When I try to execute:

java -cp .:junit-4.10.jar org.junit.runner.JUnitCore TestOne

Error: Could not find or load main class org.junit.runner.JUnitCore

How to make it work?

When I type: java aJar.jar:junit-4.10.jar org.junit.runner.JUnitCore TestOne

I am getting

Error: Could not find or load main class aJar.jar:junit-4.10.jar

回答1:


You seem to be running under Windows, not LINUX/UNIX. The path separator on Windows is ;, not :. Additionally, you haven't put you jar file in the classpath. So what you want is:

java -cp aJar.jar;junit-4.10.jar org.junit.runner.JUnitCore TestOne

This of course assumes that both jars are in the current directory. You should also always avoid putting classes in the default package.




回答2:


I had recently the same problem (JUnit 4.12) and I managed to solve it (Windows) by the following command:

java -cp "<libs>;<relative path to .class project folder>" org.junit.runner.JUnitCore <package.ClassName>

Import to notice the "" in the classpath declaration and separated by ";"



来源:https://stackoverflow.com/questions/28261167/could-not-find-or-load-main-class-org-junit-runner-junitcore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!