13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

5.3 The Java Compiler119Example 5.3 Setting the CLASSPATH envir<strong>on</strong>ment 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 c<strong>on</strong>tain classes. Each directory or JARfile is separated from the others by a col<strong>on</strong> (“:”), as shown in Example 5.3.The classpath for the compiler c<strong>on</strong>sists of the bootstrap classpath plus theuser-specified classpath. What does the classpath mean in terms of Java classnames? Think of the classpath as a list of “package roots.” In otherwords, when you refer to a class like java.sql.DriverManager ornet.multitool.SAM<strong>on</strong>ey, the Java compiler is going to go to eachentry in the combined bootstrap-and-user classpath and check there forjava/sql/DriverManager.class or net/multitool/SAM<strong>on</strong>ey.class. Ifit 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 theclasspath. In this way, compiling the single “main” class of an applicati<strong>on</strong> willoften compile the whole applicati<strong>on</strong> (we will get to excepti<strong>on</strong>s to that rule later).5.3.2 javac Opti<strong>on</strong>sThe Java compiler has many command-line opti<strong>on</strong>s that modify its behavior.We will go over the most important <strong>on</strong>es here. This is not a complete reference!See the Sun SDK Documentati<strong>on</strong> for complete reference informati<strong>on</strong>.-classpathSets the classpath. This overrides the CLASSPATH envir<strong>on</strong>ment variable, if<strong>on</strong>e is specified.-dThis switch is followed by a directory name. Compiled classes are placedin that directory. Normally, compiled classes are placed in the samedirectory as the source code.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!