Ioannis Papaioannou
Ioannis Papaioannou

Reputation: 177

I give the absolute path but java cannot a class

I cannot understand why this

ioannis@ioannis-GA-MA74GM-S2H:~$ java -cp /opt/junit4.6/junit-4.6.jar org.junit.runner.JUnitCore /opt/CalculatorTest

gives the error:

Could not find class: /opt/CalculatorTest

and this work fine:

ioannis@ioannis-GA-MA74GM-S2H:~$ java -cp /opt/junit4.6/junit-4.6.jar:/opt org.junit.runner.JUnitCore CalculatorTest
JUnit version 4.6
.
Time: 0.005

OK (1 test)

in the first I give the full path for class /opt/CalculatorTest

Upvotes: 0

Views: 144

Answers (1)

Jeanne Boyarsky
Jeanne Boyarsky

Reputation: 12266

The classname is intended to be just the class name, not a path. If it is in a package, you can have foo.Bar. If it is in the default package, you can only have Bar.

As you noticed, the classpath is the place to identify the physical directories Java should look in to find the class.

Upvotes: 1

Related Questions