Java Reference
In-Depth Information
FIGURE D-14 Execution of the Welcome program
The preceding command, after compiling the program, places the compiled code in the
same subdirectory as the program. However, when you compile a Java program using the
command-line compiler, you can instruct the system to store the program's compiled
code in any subdirectory you want. To place the compiled code in a specific directory,
you include the option -d and the name of the subdirectory where you want the
command code placed when you compile the program. For example, the command:
javac -d c:\jdk1.7.0\fastdebug\bin\classes Welcome.java
places the compiled code of the program Welcome.java in the subdirectory:
c:\jdk1.7.0\fastdebug\bin\classes
Note that the subdirectory c:\jdk1.7.0\fastdebug\bin\classes must exist before
you execute the command to compile the program.
Similarly,
the following command places
the compiled code of
the program
Welcome.java in the subdirectory c:\jpfpatpd :
javac -d c:\jpfpatpd Welcome.java
To be absolutely certain that
the directory path is correct, check your system's
documentation.
Suppose that you have placed the file Welcome.class within the subdirectory
c:\jdk1.7.0\fastdebug\bin\classes . In addition, suppose that you have not set
the CLASSPATH to allow the system to look for the compiled code on specific locations
on your computer. In this case, you can use the option -classpath and the name of
the subdirectory that contains the compiled code to execute the program. For example,
the following command looks for the compiled code of the Welcome program in the
subdirectory c:\jdk1.7.0\fastdebug\bin\classes :
java -classpath c:\jdk1.7.0\fastdebug\bin\classes Welcome
 
Search WWH ::




Custom Search