Java Reference
In-Depth Information
Example 5.3 Setting the CLASSPATH environment variable
$ export CLASSPATH=/home/mschwarz/java/simpleApp:/var/java/lib/project.jar
$ echo $CLASSPATH
/home/mschwarz/java/simpleApp:/var/java/lib/project.jar
$
directories and/or JAR or ZIP files that contain classes. Each directory or JAR
file is separated from the others by a colon (“ : ”), as shown in Example 5.3.
The classpath for the compiler consists of the bootstrap classpath plus the
user-specified classpath. What does the classpath mean in terms of Java class
names? Think of the classpath as a list of “package roots.” In other
words, when you refer to a class like java.sql.DriverManager or
net.multitool.SAMoney , the Java compiler is going to go to each
entry in the combined bootstrap-and-user classpath and check there for
java/sql/DriverManager.class or net/multitool/SAMoney.class . If
it doesn't find the .class file in a candidate directory, it will look for the
.java file. If it finds the .java file, it will compile it and then use the resulting
.class file. When it has a .class file for the class, it stops searching the
classpath. In this way, compiling the single “main” class of an application will
often compile the whole application (we will get to exceptions to that rule later).
5.3.2
The Java compiler has many command-line options that modify its behavior.
We will go over the most important ones here. This is not a complete reference!
See the Sun SDK Documentation for complete reference information.
javac Options
-classpath
Sets the classpath. This overrides the CLASSPATH environment variable, if
one is specified.
-d
This switch is followed by a directory name. Compiled classes are placed
in that directory. Normally, compiled classes are placed in the same
directory as the source code.
Search WWH ::




Custom Search