Complied Class1.java first
That's not necessary.
Class1.class was also in the same directory.
Then compile using the command:
directory containing Test.java> javac -classpath . Test.java
which shows javac the path to the classes referred to by Test.java (a "." signifies the current directory). You don't have to specify the path to Test.java itself, so if the files were in different directories, the -classpath would only specify the path to Class1.java.
The problem is if I want to run Test.class at the comand line:
When you use the java command, you have to specify all the paths to all the classes used in your program:
directory containing Test.java> javac -classpath . Test
In this case, there is only one path specified in the classpath because all the classes in the program are in the same directory. If Class1.class and Test.class were in different directories, you would have to specify the paths to both in the -classpath option.
Do I need to hard-code the classpath someplace?
Never do that. If you want to learn what's going on always specify the -classpath option. If you don't think you need to list any classpaths, then use -classpath "". If you don't use the -classpath option in your javac or java commands, then javac and java will go look in the CLASSPATH environment variable for paths, which will have you thinking no path was needed when a path in there might have been required--completely screwing up your thinking on how things work. When you include the -classpath option, it overrides anything in the CLASSPATH environment variable.
[ November 05, 2006: Message edited by: sven studde ]
[ November 05, 2006: Message edited by: sven studde ]
[ November 05, 2006: Message edited by: sven studde ]
[ November 05, 2006: Message edited by: sven studde ]
[ November 05, 2006: Message edited by: sven studde ]