javac.1 revision 0
0N/A.'" t
0N/A." Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
0N/A." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A."
0N/A." This code is free software; you can redistribute it and/or modify it
0N/A." under the terms of the GNU General Public License version 2 only, as
0N/A." published by the Free Software Foundation.
0N/A."
0N/A." This code is distributed in the hope that it will be useful, but WITHOUT
0N/A." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A." FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A." version 2 for more details (a copy is included in the LICENSE file that
0N/A." accompanied this code).
0N/A."
0N/A." You should have received a copy of the GNU General Public License version
0N/A." 2 along with this work; if not, write to the Free Software Foundation,
0N/A." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A."
0N/A." Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A." CA 95054 USA or visit www.sun.com if you need additional information or
0N/A." have any questions.
0N/A." `
0N/A.TH javac 1 "07 Aug 2006"
0N/A." Generated by html2man
0N/A
0N/A.LP
0N/A.SH NAME
0N/Ajavac \- Java programming language compiler
0N/A.LP
0N/A.SH "SYNOPSIS"
0N/A.LP
0N/A
0N/A.LP
0N/A.nf
0N/A\f3
0N/A.fl
0N/A\fP\f3javac\fP [ options ] [ sourcefiles ] [ @argfiles ]
0N/A.fl
0N/A.fi
0N/A
0N/A.LP
0N/A.LP
0N/AArguments may be in any order.
0N/A.LP
0N/A.RS 3
0N/A
0N/A.LP
0N/A.RS 3
0N/A.TP 3
0N/Aoptions
0N/ACommand\-line options.
0N/A.TP 3
0N/Asourcefiles
0N/AOne or more source files to be compiled (such as MyClass.java).
0N/A.TP 3
0N/A@argfiles
0N/AOne or more files that lists options and source files. The \f2\-J\fP options are not allowed in these files.
0N/A.RE
0N/A
0N/A.LP
0N/A.RE
0N/A.SH "DESCRIPTION"
0N/A.LP
0N/A
0N/A.LP
0N/A.LP
0N/AThe \f3javac\fP tool reads class and interface definitions, written in the Java programming language, and compiles them into bytecode class files.
0N/A.LP
0N/A.LP
0N/AThere are two ways to pass source code filenames to \f3javac\fP:
0N/A.LP
0N/A.RS 3
0N/A.TP 2
0N/Ao
0N/AFor a small number of source files, simply list the file names on the command line.
0N/A.TP 2
0N/Ao
0N/AFor a large number of source files, list the file names in a file, separated by blanks or line breaks. Then use the list file name on the \f3javac\fP command line, preceded by an \f3@\fP character.
0N/A.RE
0N/A
0N/A.LP
0N/A.LP
0N/ASource code file names must have \f2.java\fP suffixes, class file names must have \f2.class\fP suffixes, and both source and class files must have root names that identify the class. For example, a class called \f2MyClass\fP would be written in a source file called \f2MyClass.java\fP and compiled into a bytecode class file called \f2MyClass.class\fP.
0N/A.LP
0N/A.LP
0N/AInner class definitions produce additional class files. These class files have names combining the inner and outer class names, such as \f2MyClass$MyInnerClass.class\fP.
0N/A.LP
0N/A.LP
0N/AYou should arrange source files in a directory tree that reflects their package tree. For example, if you keep all your source files in \f3/workspace\fP, the source code for \f2com.mysoft.mypack.MyClass\fP should be in \f3/workspace/com/mysoft/mypack/MyClass.java\fP.
0N/A.LP
0N/A.LP
0N/ABy default, the compiler puts each class file in the same directory as its source file. You can specify a separate destination directory with \f3\-d\fP (see Options, below).
0N/A.LP
0N/A.SH "SEARCHING FOR TYPES"
0N/A.LP
0N/A
0N/A.LP
0N/A.LP
0N/AWhen compiling a source file, the compiler often needs information about a type whose definition did not appear in the source files given on the command line. The compiler needs type information for every class or interface used, extended, or implemented in the source file. This includes classes and interfaces not explicitly mentioned in the source file but which provide information through inheritance.
0N/A.LP
0N/A.LP
0N/AFor example, when you subclass \f3java.applet.Applet\fP, you are also using \f3Applet's\fP ancestor classes: \f3java.awt.Panel\fP, \f3java.awt.Container\fP, \f3java.awt.Component\fP, and \f3java.lang.Object\fP.
0N/A.LP
0N/A.LP
0N/AWhen the compiler needs type information, it looks for a source file or class file which defines the type. The compiler searches for class files first in the bootstrap and extension classes, then in the user class path (which by default is the current directory). The user class path is defined by setting the \f3CLASSPATH\fP environment variable or by using the \f3\-classpath\fP command line option. (For details, see Setting the Class Path).
0N/A.LP
0N/A.LP
0N/AIf you set the \-sourcepath option, the compiler searches the indicated path for source files; otherwise the compiler searches the user class path for both class files and source files.
0N/A.LP
0N/A.LP
0N/AYou can specify different bootstrap or extension classes with the \f3\-bootclasspath\fP and \f3\-extdirs\fP options; see Cross\-Compilation Options below.
0N/A.LP
0N/A.LP
0N/AA successful type search may produce a class file, a source file, or both. Here is how \f3javac\fP handles each situation:
0N/A.LP
0N/A.RS 3
0N/A.TP 2
0N/Ao
0N/A\f2Search produces a class file but no source file:\fP \f3javac\fP uses the class file.
0N/A.TP 2
0N/Ao
0N/A\f2Search produces a source file but no class file:\fP \f3javac\fP compiles the source file and uses the resulting class file.
0N/A.TP 2
0N/Ao
0N/A\f2Search produces both a source file and a class file:\fP \f3javac\fP determines whether the class file is out of date. If the class file is out of date, \f3javac\fP recompiles the source file and uses the updated class file. Otherwise, \f3javac\fP just uses the class file.
0N/A.LP
0N/A\f3javac\fP considers a class file out of date only if it is older than the source file.
0N/A.RE
0N/A
0N/A.LP
0N/A.LP
0N/A\f3Note:\fP \ \f3javac\fP can silently compile source files not mentioned on the command line. Use the \f3\-verbose\fP option to trace automatic compilation.
0N/A.LP
0N/A.SH "OPTIONS"
0N/A.LP
0N/A
0N/A.LP
0N/A.LP
0N/AThe compiler has a set of standard options that are supported on the current development environment and will be supported in future releases. An additional set of non\-standard options are specific to the current virtual machine and compiler implementations and are subject to change in the future. Non\-standard options begin with \f3\-X\fP.
0N/A.LP
0N/A.SS
0N/AStandard Options
0N/A.LP
0N/A.RS 3
0N/A
0N/A.LP
0N/A.RS 3
0N/A.TP 3
0N/A\-classpath classpath
0N/ASet the user class path, overriding the user class path in the \f3CLASSPATH\fP environment variable. If neither \f3CLASSPATH\fP or \f3\-classpath\fP is specified, the user class path consists of the current directory. See Setting the Class Path for more details.
0N/A.LP
0N/AIf the \f3\-sourcepath\fP option is not specified, the user class path is searched for both source files and class files.
0N/A.LP
0N/AAs a special convenience, a class path element containing a basename of \f2*\fP is considered equivalent to specifying a list of all the files in the directory with the extension \f2.jar\fP or \f2.JAR\fP (a java program cannot tell the difference between the two invocations).
0N/A.br
0N/A.br
0N/AFor example, if directory \f2foo\fP contains \f2a.jar\fP and \f2b.JAR\fP, then the class path element \f2foo/*\fP is expanded to a \f2A.jar:b.JAR\fP, except that the order of jar files is unspecified. All jar files in the specified directory, even hidden ones, are included in the list. A classpath entry consisting simply of \f2*\fP expands to a list of all the jar files in the current directory. The \f2CLASSPATH\fP environment variable, where defined, will be similarly expanded. Any classpath wildcard expansion occurs before the Java virtual machine is started \-\- no Java program will ever see unexpanded wildcards except by querying the environment. For example; by invoking \f2System.getenv("CLASSPATH")\fP.
0N/A.TP 3
0N/A\-Djava.ext.dirs=directories
0N/AOverride the location of installed extensions.
0N/A.TP 3
0N/A\-Djava.endorsed.dirs=directories
0N/AOverride the location of endorsed standards path.
0N/A.TP 3
0N/A\-d directory
0N/ASet the destination directory for class files. The destination directory must already exist; javac will not create the destination directory. If a class is part of a package, \f3javac\fP puts the class file in a subdirectory reflecting the package name, creating directories as needed. For example, if you specify \f3\-d /home/myclasses\fP and the class is called \f2com.mypackage.MyClass\fP, then the class file is called \f2/home/myclasses/com/mypackage/MyClass.class\fP.
0N/A.LP
0N/AIf \f3\-d\fP is not specified, \f3javac\fP puts the class file in the same directory as the source file.
0N/A.LP
0N/A\f3Note:\fP \ The directory specified by \f3\-d\fP is not automatically added to your user class path.
0N/A.TP 3
0N/A\-deprecation
0N/AShow a description of each use or override of a deprecated member or class. Without \f3\-deprecation\fP, \f3javac\fP shows the names of source files that use or override deprecated members or classes. \f3\-deprecation\fP is shorthand for \f3\-Xlint:deprecation\fP.
0N/A.TP 3
0N/A\-encoding encoding
0N/ASet the source file encoding name, such as \f2EUC\-JP and UTF\-8.\fP. If \f3\-encoding\fP is not specified, the platform default converter is used.
0N/A.TP 3
0N/A\-g
0N/AGenerate all debugging information, including local variables. By default, only line number and source file information is generated.
0N/A.TP 3
0N/A\-g:none
0N/ADo not generate any debugging information.
0N/A.TP 3
0N/A\-g:{keyword list}
0N/AGenerate only some kinds of debugging information, specified by a comma separated list of keywords. Valid keywords are:
0N/A.RS 3
0N/A.TP 3
0N/Asource
0N/ASource file debugging information
0N/A.TP 3
0N/Alines
0N/ALine number debugging information
0N/A.TP 3
0N/Avars
0N/ALocal variable debugging information
0N/A.RE
0N/A.TP 3
0N/A\-help
0N/APrint a synopsis of standard options.
0N/A.TP 3
0N/A\-nowarn
0N/ADisable warning messages. This has the same meaning as \f3\-Xlint:none\fP.
0N/A.LP
0N/A.TP 3
0N/A\-source release
0N/ASpecifies the version of source code accepted. The following values for \f2release\fP are allowed:
0N/A.RS 3
0N/A.TP 3
0N/A1.3
0N/AThe compiler does \f2not\fP support assertions, generics, or other language features introduced after JDK 1.3.
0N/A.TP 3
0N/A1.4
0N/AThe compiler accepts code containing assertions, which were introduced in JDK 1.4.
0N/A.TP 3
0N/A1.5
0N/AThe compiler accepts code containing generics and other language features introduced in JDK 5. This is the default.
0N/A.TP 3
0N/A5
0N/ASynonym for 1.5
0N/A.RE
0N/A\f3Note:\fP No language changes were introduced in JDK 6, so the values \f31.6\fP and \f36\fP are not valid.
0N/A.TP 3
0N/A\-sourcepath sourcepath
0N/ASpecify the source code path to search for class or interface definitions. As with the user class path, source path entries are separated by colons (\f3:\fP) and can be directories, JAR archives, or ZIP archives. If packages are used, the local path name within the directory or archive must reflect the package name.
0N/A.LP
0N/A\f3Note:\fP \ Classes found through the classpath are subject to automatic recompilation if their sources are found.
0N/A.TP 3
0N/A\-verbose
0N/AVerbose output. This includes information about each class loaded and each source file compiled.
0N/A.TP 3
0N/A\-X
0N/ADisplay information about non\-standard options and exit.
0N/A.RE
0N/A
0N/A.LP
0N/A.RE
0N/A.SS
0N/ACross\-Compilation Options
0N/A.LP
0N/A.RS 3
0N/A
0N/A.LP
0N/A.LP
0N/ABy default, classes are compiled against the bootstrap and extension classes of the platform that \f3javac\fP shipped with. But \f3javac\fP also supports \f2cross\-compiling\fP, where classes are compiled against a bootstrap and extension classes of a different Java platform implementation. It is important to use \f3\-bootclasspath\fP and \f3\-extdirs\fP when cross\-compiling; see Cross\-Compilation Example below.
0N/A.LP
0N/A.RS 3
0N/A.TP 3
0N/A\-target version
0N/AGenerate class files that target a specified version of the VM. Class files will run on the specified target and on later versions, but not on earlier versions of the VM. Valid targets are \f31.1\fP \f31.2\fP \f31.3\fP \f31.4\fP \f31.5\fP (also \f35\fP) and \f31.6\fP (also \f36\fP).
0N/A.LP
0N/AThe default for \f3\-target\fP depends on the value of \f3\-source\fP:
0N/A.RS 3
0N/A.TP 2
0N/Ao
0N/AIf \-source is \f3not specified\fP, the value of \-target is \f31.6\fP
0N/A.TP 2
0N/Ao
0N/AIf \-source is \f31.3\fP, the value of \-target is \f31.1\fP
0N/A.TP 2
0N/Ao
0N/AFor \f3all other values\fP of \-source, the value of \-target is the value of \f3\-source\fP.
0N/A.RE
0N/A.TP 3
0N/A\-bootclasspath bootclasspath
0N/ACross\-compile against the specified set of boot classes. As with the user class path, boot class path entries are separated by colons (\f3:\fP) and can be directories, JAR archives, or ZIP archives.
0N/A.TP 3
0N/A\-extdirs directories
0N/ACross\-compile against the specified extension directories. \f2Directories\fP is a colon\-separated list of directories. Each JAR archive in the specified directories is searched for class files.
0N/A.RE
0N/A
0N/A.LP
0N/A.RE
0N/A.SS
0N/ANon\-Standard Options
0N/A.LP
0N/A.RS 3
0N/A
0N/A.LP
0N/A.RS 3
0N/A.TP 3
0N/A\-Xbootclasspath/p:path
0N/APrepend to the bootstrap class path.
0N/A.TP 3
0N/A\-Xbootclasspath/a:path
0N/AAppend to the bootstrap class path.
0N/A.TP 3
0N/A\-Xbootclasspath/:path
0N/AOverride location of bootstrap class files.
0N/A.TP 3
0N/A\-Xlint
0N/AEnable all recommended warnings. In this release, all available warnings are recommended.
0N/A.TP 3
0N/A\-Xlint:none
0N/ADisable all warnings not mandated by the Java Language Specification.
0N/A.TP 3
0N/A\-Xlint:\-xxx
0N/ADisable warning \f3xxx\fP, where \f3xxx\fP is one of the warning names supported for \f3\-Xlint:xxx\fP, below
0N/A.TP 3
0N/A\-Xlint:unchecked
0N/AGive more detail for unchecked conversion warnings that are mandated by the Java Language Specification.
0N/A.TP 3
0N/A\-Xlint:path
0N/AWarn about nonexistent path (classpath, sourcepath, etc) directories.
0N/A.TP 3
0N/A\-Xlint:serial
0N/AWarn about missing \f2serialVersionUID\fP definitions on serializable classes.
0N/A.TP 3
0N/A\-Xlint:finally
0N/AWarn about \f2finally\fP clauses that cannot complete normally.
0N/A.TP 3
0N/A\-Xlint:fallthrough
0N/ACheck \f2switch\fP blocks for fall\-through cases and provide a warning message for any that are found. Fall\-through cases are cases in a \f2switch\fP block, other than the last case in the block, whose code does not include a \f2break\fP statement, allowing code execution to "fall through" from that case to the next case. For example, the code following the \f2case 1\fP label in this \f2switch\fP block does not contain a \f2break\fP statement:
0N/A.RS 3
0N/A
0N/A.LP
0N/A.nf
0N/A\f3
0N/A.fl
0N/Aswitch (x) {
0N/A.fl
0N/Acase 1:
0N/A.fl
0N/A System.out.println("1");
0N/A.fl
0N/A // No break; statement here.
0N/A.fl
0N/Acase 2:
0N/A.fl
0N/A System.out.println("2");
0N/A.fl
0N/A}
0N/A.fl
0N/A\fP
0N/A.fi
0N/A.RE
0N/AIf the \f2\-Xlint:fallthrough\fP flag were used when compiling this code, the compiler would emit a warning about "possible fall\-through into case," along with the line number of the case in question.
0N/A.TP 3
0N/A\-Xmaxerrors number
0N/ASet the maximum number of errors to print.
0N/A.TP 3
0N/A\-Xmaxwarns number
0N/ASet the maximum number of warnings to print.
0N/A.TP 3
0N/A\-Xstdout filename
0N/ASend compiler messages to the named file. By default, compiler messages go to \f2System.err\fP.
0N/A.RE
0N/A
0N/A.LP
0N/A.RE
0N/A.SS
0N/AThe \-J Option
0N/A.LP
0N/A.RS 3
0N/A
0N/A.LP
0N/A.RS 3
0N/A.TP 3
0N/A\-Joption
0N/APass \f2option\fP to the \f3java\fP launcher called by \f3javac\fP. For example, \f3\-J\-Xms48m\fP sets the startup memory to 48 megabytes. Although it does not begin with \f3\-X\fP, it is not a `standard option' of \f3javac\fP. It is a common convention for \f3\-J\fP to pass options to the underlying VM executing applications written in Java.
0N/A.LP
0N/A\f3Note:\fP \ \f3CLASSPATH\fP, \f3\-classpath\fP, \f3\-bootclasspath\fP, and \f3\-extdirs\fP do \f2not\fP specify the classes used to run \f3javac\fP. Fiddling with the implementation of the compiler in this way is usually pointless and always risky. If you do need to do this, use the \f3\-J\fP option to pass through options to the underlying \f3java\fP launcher.
0N/A.RE
0N/A
0N/A.LP
0N/A.RE
0N/A.SH "COMMAND LINE ARGUMENT FILES"
0N/A.LP
0N/A
0N/A.LP
0N/A.LP
0N/ATo shorten or simplify the javac command line, you can specify one or more files that themselves contain arguments to the \f2javac\fP command (except \f2\-J\fP options). This enables you to create javac commands of any length on any operating system.
0N/A.LP
0N/A.LP
0N/AAn argument file can include javac options and source filenames in any combination. The arguments within a file can be space\-separated or newline\-separated. If a filename contains embedded spaces, put the whole filename in double quotes.
0N/A.LP
0N/A.LP
0N/AFilenames within an argument file are relative to the current directory, not the location of the argument file. Wildcards (*) are not allowed in these lists (such as for specifying \f2*.java\fP). Use of the '\f2@\fP' character to recursively interpret files is not supported. The \f2\-J\fP options are not supported because they are passed to the launcher, which does not support argument files.
0N/A.LP
0N/A.LP
0N/AWhen executing javac, pass in the path and name of each argument file with the '\f2@\fP' leading character. When javac encounters an argument beginning with the character `\f2@\fP', it expands the contents of that file into the argument list.
0N/A.LP
0N/A.SS
0N/AExample \- Single Arg File
0N/A.LP
0N/A.LP
0N/AYou could use a single argument file named "\f2argfile\fP" to hold all javac arguments:
0N/A.LP
0N/A.nf
0N/A\f3
0N/A.fl
0N/A C:> \fP\f3javac @argfile\fP
0N/A.fl
0N/A.fi
0N/A
0N/A.LP
0N/A.LP
0N/AThis argument file could contain the contents of both files shown in the next example.
0N/A.LP
0N/A.SS
0N/AExample \- Two Arg Files
0N/A.LP
0N/A.LP
0N/AYou can create two argument files \-\- one for the javac options and the other for the source filenames: (Notice the following lists have no line\-continuation characters.)
0N/A.LP
0N/A.LP
0N/ACreate a file named "\f2options\fP" containing:
0N/A.LP
0N/A.nf
0N/A\f3
0N/A.fl
0N/A \-d classes
0N/A.fl
0N/A \-g
0N/A.fl
0N/A \-sourcepath \\java\\pubs\\ws\\1.3\\src\\share\\classes
0N/A.fl
0N/A\fP
0N/A.fi
0N/A
0N/A.LP
0N/A.LP
0N/ACreate a file named "\f2classes\fP" containing:
0N/A.LP
0N/A.nf
0N/A\f3
0N/A.fl
0N/A MyClass1.java
0N/A.fl
0N/A MyClass2.java
0N/A.fl
0N/A MyClass3.java
0N/A.fl
0N/A\fP
0N/A.fi
0N/A
0N/A.LP
0N/A.LP
0N/AYou would then run javac with:
0N/A.LP
0N/A.nf
0N/A\f3
0N/A.fl
0N/A % \fP\f3javac @options @classes\fP
0N/A.fl
0N/A.fi
0N/A
0N/A.LP
0N/A.SS
0N/AExample \- Arg Files with Paths
0N/A.LP
0N/A.LP
0N/AThe argument files can have paths, but any filenames inside the files are relative to the current working directory (not \f2path1\fP or \f2path2\fP):
0N/A.LP
0N/A.nf
0N/A\f3
0N/A.fl
0N/A % \fP\f3javac @path1/options @path2/classes\fP
0N/A.fl
0N/A.fi
0N/A
0N/A.LP
0N/A.SH "PROGRAMMATIC INTERFACE"
0N/A.LP
0N/A.LP
0N/AThe \f2com.sun.tools.javac.Main\fP class provides two static methods to invoke the compiler from a program:
0N/A.LP
0N/A.nf
0N/A\f3
0N/A.fl
0N/Apublic static int compile(String[] args);
0N/A.fl
0N/Apublic static int compile(String[] args, PrintWriter out);
0N/A.fl
0N/A\fP
0N/A.fi
0N/A
0N/A.LP
0N/A.LP
0N/AThe \f2args\fP parameter represents any of the command line arguments that would normally be passed to the javac program and are outlined in the above Synopsis section.
0N/A.LP
0N/A.LP
0N/AThe \f2out\fP parameter indicates where the compiler's diagnostic output is directed.
0N/A.LP
0N/A.LP
0N/AThe return value is equivalent to the exit value from javac.
0N/A.LP
0N/A.LP
0N/ANote that all \f3other\fP classes and methods found in a package whose name starts with \f2com.sun.tools.javac\fP (informally known as sub\-packages of \f2com.sun.tools.javac\fP) are strictly internal and subject to change at any time.
0N/A.LP
0N/A.SH "EXAMPLES"
0N/A.LP
0N/A.SS
0N/ACompiling a Simple Program
0N/A.LP
0N/A.RS 3
0N/A
0N/A.LP
0N/A.LP
0N/AOne source file, \f2Hello.java\fP, defines a class called \f3greetings.Hello\fP. The \f2greetings\fP directory is the package directory both for the source file and the class file and is off the current directory. This allows us to use the default user class path. It also makes it unnecessary to specify a separate destination directory with \f3\-d\fP.
0N/A.LP
0N/A.RS 3
0N/A
0N/A.LP
0N/A.nf
0N/A\f3
0N/A.fl
0N/A% \fP\f3ls\fP
0N/A.fl
0N/Agreetings/
0N/A.fl
0N/A% \f3ls greetings\fP
0N/A.fl
0N/AHello.java
0N/A.fl
0N/A% \f3cat greetings/Hello.java\fP
0N/A.fl
0N/Apackage greetings;
0N/A.fl
0N/A
0N/A.fl
0N/Apublic class Hello {
0N/A.fl
0N/A public static void main(String[] args) {
0N/A.fl
0N/A for (int i=0; i < args.length; i++) {
0N/A.fl
0N/A System.out.println("Hello " + args[i]);
0N/A.fl
0N/A }
0N/A.fl
0N/A }
0N/A.fl
0N/A}
0N/A.fl
0N/A% \f3javac greetings/Hello.java\fP
0N/A.fl
0N/A% \f3ls greetings\fP
0N/A.fl
0N/AHello.class Hello.java
0N/A.fl
0N/A% \f3java greetings.Hello World Universe Everyone\fP
0N/A.fl
0N/AHello World
0N/A.fl
0N/AHello Universe
0N/A.fl
0N/AHello Everyone
0N/A.fl
0N/A.fi
0N/A.RE
0N/A
0N/A.LP
0N/A.RE
0N/A.SS
0N/ACompiling Multiple Source Files
0N/A.LP
0N/A.RS 3
0N/A
0N/A.LP
0N/A.LP
0N/AThis example compiles all the source files in the package \f2greetings\fP.
0N/A.LP
0N/A.RS 3
0N/A
0N/A.LP
0N/A.nf
0N/A\f3
0N/A.fl
0N/A% \fP\f3ls\fP
0N/A.fl
0N/Agreetings/
0N/A.fl
0N/A% \f3ls greetings\fP
0N/A.fl
0N/AAloha.java GutenTag.java Hello.java Hi.java
0N/A.fl
0N/A% \f3javac greetings/*.java\fP
0N/A.fl
0N/A% \f3ls greetings\fP
0N/A.fl
0N/AAloha.class GutenTag.class Hello.class Hi.class
0N/A.fl
0N/AAloha.java GutenTag.java Hello.java Hi.java
0N/A.fl
0N/A
0N/A.fl
0N/A.fi
0N/A.RE
0N/A
0N/A.LP
0N/A.RE
0N/A.SS
0N/ASpecifying a User Class Path
0N/A.LP
0N/A.RS 3
0N/A
0N/A.LP
0N/A.LP
0N/AHaving changed one of the source files in the previous example, we recompile it:
0N/A.LP
0N/A.RS 3
0N/A
0N/A.LP
0N/A.nf
0N/A\f3
0N/A.fl
0N/A% \fP\f3pwd\fP
0N/A.fl
0N/A/examples
0N/A.fl
0N/A% \f3javac greetings/Hi.java\fP
0N/A.fl
0N/A.fi
0N/A.RE
0N/A
0N/A.LP
0N/A.LP
0N/ASince \f2greetings.Hi\fP refers to other classes in the \f2greetings\fP package, the compiler needs to find these other classes. The example above works, because our default user class path happens to be the directory containing the package directory. But suppose we want to recompile this file and not worry about which directory we're in? Then we need to add \f2/examples\fP to the user class path. We can do this by setting \f3CLASSPATH\fP, but here we'll use the \f3\-classpath\fP option.
0N/A.LP
0N/A.RS 3
0N/A
0N/A.LP
0N/A.nf
0N/A\f3
0N/A.fl
0N/A% \fP\f3javac \-classpath /examples /examples/greetings/Hi.java\fP
0N/A.fl
0N/A.fi
0N/A.RE
0N/A
0N/A.LP
0N/A.LP
0N/AIf we change \f2greetings.Hi\fP again, to use a banner utility, that utility also needs to be accessible through the user class path.
0N/A.LP
0N/A.RS 3
0N/A
0N/A.LP
0N/A.nf
0N/A\f3
0N/A.fl
0N/A% \fP\f3javac \-classpath /examples:/lib/Banners.jar \\
0N/A.fl
0N/A /examples/greetings/Hi.java\fP
0N/A.fl
0N/A.fi
0N/A.RE
0N/A
0N/A.LP
0N/A.LP
0N/ATo execute a class in \f2greetings\fP, we need access both to \f2greetings\fP and to the classes it uses.
0N/A.LP
0N/A.RS 3
0N/A
0N/A.LP
0N/A.nf
0N/A\f3
0N/A.fl
0N/A% \fP\f3java \-classpath /examples:/lib/Banners.jar greetings.Hi\fP
0N/A.fl
0N/A.fi
0N/A.RE
0N/A
0N/A.LP
0N/A.RE
0N/A.SS
0N/ASeparating Source Files and Class Files
0N/A.LP
0N/A.RS 3
0N/A
0N/A.LP
0N/A.LP
0N/AIt often makes sense to keep source files and class files in separate directories, especially on large projects. We use \f3\-d\fP to indicate the separate class file destination. Since the source files are not in the user class path, we use \f3\-sourcepath\fP to help the compiler find them.
0N/A.LP
0N/A.RS 3
0N/A
0N/A.LP
0N/A.nf
0N/A\f3
0N/A.fl
0N/A% \fP\f3ls\fP
0N/A.fl
0N/Aclasses/ lib/ src/
0N/A.fl
0N/A% \f3ls src\fP
0N/A.fl
0N/Afarewells/
0N/A.fl
0N/A% \f3ls src/farewells\fP
0N/A.fl
0N/ABase.java GoodBye.java
0N/A.fl
0N/A% \f3ls lib\fP
0N/A.fl
0N/ABanners.jar
0N/A.fl
0N/A% \f3ls classes\fP
0N/A.fl
0N/A% \f3javac \-sourcepath src \-classpath classes:lib/Banners.jar \\
0N/A.fl
0N/A src/farewells/GoodBye.java \-d classes\fP
0N/A.fl
0N/A% \f3ls classes\fP
0N/A.fl
0N/Afarewells/
0N/A.fl
0N/A% \f3ls classes/farewells\fP
0N/A.fl
0N/ABase.class GoodBye.class
0N/A.fl
0N/A
0N/A.fl
0N/A.fi
0N/A.RE
0N/A
0N/A.LP
0N/A.LP
0N/A\f3Note:\fP \ The compiler compiled \f2src/farewells/Base.java\fP, even though we didn't specify it on the command line. To trace automatic compiles, use the \f3\-verbose\fP option.
0N/A.LP
0N/A.RE
0N/A.SS
0N/ACross\-Compilation Example
0N/A.LP
0N/A.RS 3
0N/A
0N/A.LP
0N/A.LP
0N/AHere we use \f3javac\fP to compile code that will run on a 1.4 VM.
0N/A.LP
0N/A.RS 3
0N/A
0N/A.LP
0N/A.nf
0N/A\f3
0N/A.fl
0N/A% \fP\f3javac \-target 1.4 \-bootclasspath jdk1.4.2/lib/classes.zip \\
0N/A.fl
0N/A \-extdirs "" OldCode.java\fP
0N/A.fl
0N/A.fi
0N/A.RE
0N/A
0N/A.LP
0N/A.LP
0N/AThe \f3\-target 1.4\fP option ensures that the generated class files will be compatible with 1.4 VMs. By default, \f3javac\fP compiles for JDK 6.
0N/A.LP
0N/A.LP
0N/AThe Java Platform JDK's \f3javac\fP would also by default compile against its own bootstrap classes, so we need to tell \f3javac\fP to compile against JDK 1.4 bootstrap classes instead. We do this with \f3\-bootclasspath\fP and \f3\-extdirs\fP. Failing to do this might allow compilation against a Java Platform API that would not be present on a 1.4 VM and would fail at runtime.
0N/A.LP
0N/A.RE
0N/A.SH "SEE ALSO"
0N/A.LP
0N/A
0N/A.LP
0N/A.RS 3
0N/A.TP 2
0N/Ao
0N/Ajava \- the Java Application Launcher
0N/A.TP 2
0N/Ao
0N/Ajdb \- Java Application Debugger
0N/A.TP 2
0N/Ao
0N/Ajavah \- C Header and Stub File Generator
0N/A.TP 2
0N/Ao
0N/Ajavap \- Class File Disassembler
0N/A.TP 2
0N/Ao
0N/Ajavadoc \- API Documentation Generator
0N/A.TP 2
0N/Ao
0N/Ajar \- JAR Archive Tool
0N/A.TP 2
0N/Ao
0N/A.na
0N/A\f2The Java Extensions Framework\fP @
0N/A.fi
0N/Ahttp://java.sun.com/javase/6/docs/technotes/guides/extensions/index.html
0N/A.RE
0N/A
0N/A.LP
0N/A
0N/A.LP
0N/A
0N/A