posted 24 years ago
Or you can specify the -d option to the javac compiler. This option tells the compiler where to put your output. It will also create the directory matching your package definition. Later you can use the -classpath option when you're invoking the JVM to the same directory and the JVM will find the correct class in the package hierarchy. Note, you have to specify the package with the class name when using this technique.
-Peter
If I compile this code with the command javac -d c:\work\lib Bar.java, the compiler will create the following directory structure for me (assuming it hasn't already existed). Additional note, the directory structure c:\work\lib should already exist. The compiler only creates your directory structure matching your package name.
<pre>
c:\work
|_lib
|_com
|_peter
|_foo
|_Bar.class
</pre>
Now to invoke the main() method of class Bar, I can drill down the directory structure:
java c:\work\lib\com\peter\foo\Bar
Or provide the package and class name and use the -classpath option to specify where to start looking for the root of my class.
java -classpath c:\work\lib com.peter.foo.Bar
Notice the package name with the class name. This is required when you're provide the root package using the classpath option.
-Peter
[This message has been edited by Peter Tran (edited January 15, 2001).]
[This message has been edited by Peter Tran (edited January 15, 2001).]