5

I've got the following structure

lib/junit-4.10.jar
tests/Tester.java
tests/Tester.class
build/jar/jar_file.jar

(Tester belongs to package tests)

I can compile tests using

javac -cp build/jar/jar_file.jar:lib/junit-4.10.jar tests/*.java

However I can't seem to run tests:

java -cp build/jar/jar_file.jar:lib/junit-4.10.jar org.junit.runner.JUnitCore tests.Tester

or

java -cp build/jar/jar_file.jar:lib/junit-4.10.jar org.junit.runner.JUnitCore Tester

And I get the following output:

JUnit version 4.10
Could not find class: tests.Tester

Time: 0.001

OK (0 tests)

How do I resolve this Could not find class problem? I think it may be classpath related.

4

2 回答 2

9

假设这是 Linux/Mac(不是 Windows)并且您的路径分隔符是正确的 (:),因为您的测试类文件存在于当前工作目录下的包子目录中 (.) 您需要添加“。” 到你的类路径,例如:

java -cp .:build/jar/jar_file.jar:lib/junit-4.10.jar org.junit.runner.JUnitCore tests.Tester
于 2012-10-30T19:53:06.013 回答
1

类路径应该用分号分隔(在 Windows 上 - 不确定您使用的是什么。)

java -cp build/jar/jar_file.jar;lib/junit-4.10.jar org.junit.runner.JUnitCore tests.Tester

同样使用此命令行,您需要在项目根目录中运行它

于 2012-10-30T19:51:40.927 回答