It says that the class that it cannot find is Tester.GUI.api.Test1
. What directory are you running the test from, and what directory is your Test1
code in?
If you set the -classpath
variable, you may also need to include the current directory in your classpath. So, if your original command was
java -classpath C:\foo.jar;D:\bar1\bar2.jar org.junit.runner.JUnitCore Tester.GUI.api.Test1
you could add the current directory to your classpath by adding ;.
to the end of your -classpath
option like this:
java -classpath C:\foo.jar;D:\bar1\bar2.jar;. org.junit.runner.JUnitCore Tester.GUI.api.Test1
This will work as long as the Test1
class is in the Tester\GUI\api
directory under the current directory.
The tricky thing with setting the classpath in Java is that you don't want to give the directory where your actual .java files are, but instead you want to give the directory under which you can find the directories that are named for the packages in your code.
For example, if I compiled a class Foo
in a package bar.baz
, then I should have a file named Foo.class
in a directory named baz
inside another directory named bar
. If I want to include Foo
in my classpath, and if Foo.class
is located at
C:\Users\Joe\Code\bar\baz\Foo.class
, then I have to either run
java -classpath C:\Users\Joe\Code [main class goes here]
or else I have to change my directory to C:\Users\Joe\Code
and run
java -classpath . [main class goes here]