Reputation: 3352
I failed specifying the class path. Here's my setup:
File: "root/src/hello/German.java"
package hello;
public class German {
public void greet() { System.out.println("Hallo"); }
}
I compile this in "root":
> javac root/src/hello/German.java -d root/package
where "root/package/hello" exists as an empty directory. Fine. Now I want to test and write
File: "root/test/testHello.java"
import hello.German;
public class helloTest {
public static void main(String[] args) {
German guy = new German();
guy.greet();
}
}
I compile
> javac testHello.java -cp ../package
To summarize, I have:
I execute in "root/test/":
> java testHello => class not found except.
> java testHello -cp ../package => class not found except.
> java testHello -cp ../package/hello => class not found except.
However, copying the 'hello' directory into test such that there is
I can execute in "root/test/"
> java testHello
and it greets friendly in German. I want to specify the classpath, though. But, I have no idea why '-cp' and '-classpath' is not accepted.
Upvotes: 2
Views: 68
Reputation: 1854
Try this:
java -classpath .:../package testHello
.:../package
to use the current directory and ../package
as classpath.
Upvotes: 1