posted 13 years ago
I came across this issue whilst attempting a practice question in Sierra & Bates p818 q12.
Suppose I have HelloWorld.java and a directory testdir in the current directory.
I can compile HelloWorld, even if I supply a command line classpath that does not include the current directory:
javac -classpath testdir HelloWorld.java
So, given that the file I want to compile was supplied as an argument, javac can find it, even though the supplied classpath didn't tell it to look in the current directory. (Were HelloWorld.java to use some other class, also in this same directory, the compile would fail.)
Now I try to launch HelloWorld.class, using the same classpath:
java -classpath testdir HelloWorld
I get an error, "Error: Could not find or load main class in HelloWorld"
I have to include the current directory in the supplied classpath:
java -classpath testdir;. HelloWorld
Now it works.
So, am I right in thinking that the way java & javac use the -classpath argument is slightly different, in that javac automatically adds . to it?
Regards
Richard