javac.1 revision 1178
4169N/A." Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved.
1178N/A." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1178N/A."
1178N/A." This code is free software; you can redistribute it and/or modify it
1178N/A." under the terms of the GNU General Public License version 2 only, as
1178N/A." published by the Free Software Foundation.
1178N/A."
1178N/A." This code is distributed in the hope that it will be useful, but WITHOUT
1178N/A." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1178N/A." FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1178N/A." version 2 for more details (a copy is included in the LICENSE file that
1178N/A." accompanied this code).
1178N/A."
1178N/A." You should have received a copy of the GNU General Public License version
1178N/A." 2 along with this work; if not, write to the Free Software Foundation,
1178N/A." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1178N/A."
2362N/A." Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
2362N/A." CA 95054 USA or visit www.sun.com if you need additional information or
2362N/A." have any questions.
1178N/A."
5176N/A.TH javac 1 "04 May 2009"
1178N/A." Generated from HTML by html2man (author: Eric Armstrong)
0N/A
4033N/A.LP
4935N/A.SH "Name"
1178N/Ajavac \- Java programming language compiler
4935N/A.LP
4033N/A.SH "SYNOPSIS"
0N/A.LP
1178N/A
1178N/A.LP
1178N/A.nf
1178N/A\f3
1178N/A.fl
1178N/A \fP\f3javac\fP [ options ] [ sourcefiles ] [ classes ] [ @argfiles ]
0N/A.fl
1178N/A
1178N/A.fl
1178N/A.fi
4935N/A
1178N/A.LP
4033N/A.LP
0N/AArguments may be in any order.
4033N/A.LP
4935N/A.RS 3
1178N/A
1178N/A.LP
0N/A.RS 3
5176N/A.TP 3
4033N/Aoptions
1178N/ACommand\-line options.
4935N/A.TP 3
4033N/Asourcefiles
4033N/AOne or more source files to be compiled (such as MyClass.java).
4935N/A.TP 3
0N/Aclasses
4033N/AOne or more classes to be processed for annotations (such as MyPackage.MyClass).
4033N/A.TP 3
4033N/A@argfiles
4033N/AOne or more files that lists options and source files. The \f2\-J\fP options are not allowed in these files.
4033N/A.RE
4033N/A
4033N/A.LP
4033N/A.RE
4033N/A.SH "DESCRIPTION"
4033N/A.LP
4033N/A
4033N/A.LP
4033N/A.LP
4033N/AThe \f3javac\fP tool reads class and interface definitions, written in the Java programming language, and compiles them into bytecode class files. It can also process annotations in Java source files and classes.
4033N/A.LP
4033N/A.LP
4033N/AThere are two ways to pass source code file names to \f3javac\fP:
4033N/A.LP
1178N/A.RS 3
0N/A.TP 2
0N/Ao
4033N/AFor a small number of source files, simply list the file names on the command line.
1178N/A.TP 2
4033N/Ao
4033N/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.
4033N/A.RE
4033N/A
4033N/A.LP
4033N/A.LP
4033N/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
1178N/A.LP
4935N/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.
4033N/A.LP
4033N/A.LP
4033N/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.
4033N/A.LP
4033N/A.LP
4033N/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).
4033N/A.LP
4033N/A.SH "OPTIONS"
4033N/A.LP
4033N/A
1178N/A.LP
0N/A.LP
4935N/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
4935N/AStandard Options
4033N/A.LP
4033N/A.RS 3
4935N/A
0N/A.LP
1178N/A.RS 3
0N/A.TP 3
5176N/A\-Akey[=value]
1178N/AOptions to pass to annotation processors. These are not interpreted by javac directly, but are made available for use by individual processors. \f2key\fP should be one or more identifiers separated by ".".
0N/A.TP 3
0N/A\-cp path or \-classpath path
4935N/ASpecify where to find user class files, and (optionally) annotation processors and source files. This classpath overrides the user class path in the \f3CLASSPATH\fP environment variable. If neither \f3CLASSPATH\fP, \f3\-cp\fP nor \f3\-classpath\fP is specified, the user class path consists of the current directory. See
0N/A.na
5176N/A\f2Setting the Class Path\fP @
4033N/A.fi
4033N/Ahttp://java.sun.com/javase/6/docs/technotes/tools/index.html#classpath for more details.
4935N/A.LP
4033N/AIf the \f3\-sourcepath\fP option is not specified, the user class path is also searched for source files.
4033N/A.LP
4033N/AIf the \f3\-processorpath\fP option is not specified, the classpath is also searched for annotation processors.
4033N/A.LP
4033N/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.
4033N/A.br
4033N/A.br
4033N/AFor example, if directory \f2foo\fP contains \f2a.jar\fP and \f2b.JAR\fP, then the class path element \f2foo/*\fP is expanded to \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. \f3Note:\fP \ Depending of the configuration of your command line environment, you may have to quote the wild card character, for example, \f2javac \-cp "*.jar" MyClass.java\fP.
4033N/A.TP 3
4033N/A\-Djava.ext.dirs=directories
0N/AOverride the location of installed extensions.
0N/A.TP 3
4935N/A\-Djava.endorsed.dirs=directories
0N/AOverride the location of endorsed standards path.
1178N/A.TP 3
4935N/A\-d directory
1178N/ASet the destination directory for class files. The directory must already exist; \f3javac\fP will not create it. 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.
4033N/A.LP
4033N/AIf \f3\-d\fP is not specified, \f3javac\fP puts each class files in the same directory as the source file from which it was generated.
4033N/A.LP
4033N/A\f3Note:\fP \ The directory specified by \f3\-d\fP is not automatically added to your user class path.
4033N/A.TP 3
4033N/A\-deprecation
4033N/AShow a description of each use or override of a deprecated member or class. Without \f3\-deprecation\fP, \f3javac\fP shows a summary of the source files that use or override deprecated members or classes. \f3\-deprecation\fP is shorthand for \f3\-Xlint:deprecation\fP.
4033N/A.TP 3
4033N/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.
1178N/A.TP 3
4935N/A\-g
4033N/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
1178N/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
1178N/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\-implicit:{class,none}
0N/AControls the generation of class files for implicitly loaded source files. To automatically generate class files, use \f3\-implicit:class\fP. To suppress class file generation, use \f3\-implicit:none\fP. If this option is not specified, the default is to automatically generate class files. In this case, the compiler will issue a warning if any such class files are generated when also doing annotation processing. The warning will not be issued if this option is set explicitly. See Searching For Types.
1178N/A.TP 3
0N/A\-nowarn
0N/ADisable warning messages. This has the same meaning as \f3\-Xlint:none\fP.
0N/A.TP 3
0N/A\-proc: {none,only}
0N/AControls whether annotation processing and/or compilation is done. \f3\-proc:none\fP means that compilation takes place without annotation processing. \f3\-proc:only\fP means that only annotation processing is done, without any subsequent compilation.
1178N/A.TP 3
0N/A\-processor class1[,class2,class3...]
0N/ANames of the annotation processors to run. This bypasses the default discovery process.
0N/A.TP 3
0N/A\-processorpath path
0N/ASpecify where to find annotation processors; if this option is not used, the classpath will be searched for processors.
0N/A.TP 3
0N/A\-s dir
0N/ASpecify the directory where to place generated source files. The directory must already exist; \f3javac\fP will not create it. If a class is part of a package, the compiler puts the source file in a subdirectory reflecting the package name, creating directories as needed. For example, if you specify \f3\-s /home/mysrc\fP and the class is called \f2com.mypackage.MyClass\fP, then the source file will be placed in \f2/home/mysrc/com/mypackage/MyClass.java\fP.
4935N/A.TP 3
0N/A\-source release
1178N/ASpecifies the version of source code accepted. The following values for \f2release\fP are allowed:
4935N/A.RS 3
4033N/A.TP 3
4033N/A1.3
4033N/AThe compiler does \f2not\fP support assertions, generics, or other language features introduced after JDK 1.3.
4033N/A.TP 3
4033N/A1.4
4033N/AThe compiler accepts code containing assertions, which were introduced in JDK 1.4.
4033N/A.TP 3
4033N/A1.5
4033N/AThe compiler accepts code containing generics and other language features introduced in JDK 5.
4033N/A.TP 3
4033N/A5
4033N/ASynonym for 1.5.
4935N/A.TP 3
0N/A1.6
0N/AThis is the default value. No language changes were introduced in Java SE 6. However, encoding errors in source files are now reported as errors, instead of warnings, as previously.
0N/A.TP 3
0N/A6
0N/ASynonym for 1.6.
0N/A.TP 3
0N/A1.7
0N/AThe compiler accepts code with features introduced in JDK 7.
1178N/A.TP 3
0N/A7
0N/ASynonym for 1.7.
0N/A.RE
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
1178N/A\f3Note:\fP \ Classes found through the classpath may be subject to automatic recompilation if their sources are also found. See Searching For Types.
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\-version
1178N/APrint version information.
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
1178N/A.SS
4033N/ACross\-Compilation Options
4033N/A.LP
4033N/A.RS 3
4935N/A
0N/A.LP
4033N/A.LP
4033N/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.
4033N/A.LP
4033N/A.RS 3
4033N/A.TP 3
4033N/A\-target version
1178N/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) \f31.6\fP (also \f36\fP) and \f31.7\fP (also \f37\fP).
0N/A.LP
4033N/AThe default for \f3\-target\fP depends on the value of \f3\-source\fP:
4935N/A.RS 3
4033N/A.TP 2
4033N/Ao
4935N/AIf \-source is \f3not specified\fP, the value of \-target is \f31.6\fP
4033N/A.TP 2
4033N/Ao
4935N/AIf \-source is \f31.2\fP, the value of \-target is \f31.4\fP
4033N/A.TP 2
4033N/Ao
4033N/AIf \-source is \f31.3\fP, the value of \-target is \f31.4\fP
4033N/A.TP 2
4033N/Ao
4033N/AFor \f3all other values\fP of \-source, the value of \-target is the value of \f3\-source\fP.
4033N/A.RE
4033N/A.TP 3
4033N/A\-bootclasspath bootclasspath
4033N/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.
4935N/A.TP 3
4033N/A\-extdirs directories
4033N/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.
4033N/A.RE
4033N/A
4033N/A.LP
4033N/A.RE
4033N/A.SS
1178N/ANon\-Standard Options
0N/A.LP
4033N/A.RS 3
4935N/A
0N/A.LP
4033N/A.RS 3
4033N/A.TP 3
4033N/A\-Xbootclasspath/p:path
4033N/APrepend to the bootstrap class path.
4033N/A.TP 3
4033N/A\-Xbootclasspath/a:path
4033N/AAppend to the bootstrap class path.
1178N/A.TP 3
0N/A\-Xbootclasspath/:path
1178N/AOverride location of bootstrap class files.
4935N/A.TP 3
1178N/A\-Xlint
4935N/AEnable all recommended warnings. In this release, all available warnings are recommended.
0N/A.TP 3
5176N/A\-Xlint:none
4033N/ADisable all warnings not mandated by the Java Language Specification.
1178N/A.TP 3
4935N/A\-Xlint:\-name
4033N/ADisable warning \f2name\fP, where \f2name\fP is one of the warning names supported for \f3\-Xlint:\fP\f2name\fP, below.
4033N/A.TP 3
4935N/A\-Xlint:unchecked
4033N/AGive more detail for unchecked conversion warnings that are mandated by the Java Language Specification.
4033N/A.TP 3
4033N/A\-Xlint:path
4033N/AWarn about nonexistent path (classpath, sourcepath, etc) directories.
4033N/A.TP 3
0N/A\-Xlint:serial
4033N/AWarn about missing \f2serialVersionUID\fP definitions on serializable classes.
4033N/A.TP 3
4033N/A\-Xlint:finally
4033N/AWarn about \f2finally\fP clauses that cannot complete normally.
4033N/A.TP 3
4033N/A\-Xlint:fallthrough
4033N/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 end with a \f2break\fP statement:
4033N/A.RS 3
4033N/A
4033N/A.LP
4033N/A.nf
4033N/A\f3
4033N/A.fl
1178N/Aswitch (x) {
0N/A.fl
4033N/Acase 1:
1178N/A.fl
4033N/A System.out.println("1");
4033N/A.fl
0N/A // No break; statement here.
4033N/A.fl
4033N/Acase 2:
4033N/A.fl
4033N/A System.out.println("2");
4033N/A.fl
4033N/A}
4033N/A.fl
4033N/A
4033N/A.fl
4033N/A\fP
4033N/A.fi
4033N/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.
4033N/A.TP 3
0N/A\-Xmaxerrs number
0N/ASet the maximum number of errors to print.
4935N/A.TP 3
0N/A\-Xmaxwarns number
4033N/ASet the maximum number of warnings to print.
4033N/A.TP 3
4033N/A\-Xstdout filename
4033N/ASend compiler messages to the named file. By default, compiler messages go to \f2System.err\fP.
4033N/A.TP 3
4033N/A\-Xprefer:{newer,source}
4033N/ASpecify which file to read when both a source file and class file are found for a type. (See Searching For Types). If \f2\-Xprefer:newer\fP is used, it reads the newer of the source or class file for a type (default). If the \f2\-Xprefer:source\fP option is used, it reads source file. Use \f2\-Xprefer:source\fP when you want to be sure that any annotation processors can access annotations declared with a retention policy of \f2SOURCE\fP.
4033N/A.TP 3
0N/A\-Xprint
0N/APrint out textual representation of specified types for debugging purposes; perform neither annotation processing nor compilation. The format of the output may change.
4935N/A.TP 3
1178N/A\-XprintProcessorInfo
4033N/APrint information about which annotations a processor is asked to process.
4033N/A.TP 3
4033N/A\-XprintRounds
4033N/APrint information about initial and subsequent annotation processing rounds.
4033N/A.RE
4033N/A
0N/A.LP
0N/A.RE
1178N/A.SS
4935N/AThe \-J Option
1178N/A.LP
4033N/A.RS 3
1178N/A
1178N/A.LP
4033N/A.RS 3
1178N/A.TP 3
4033N/A\-Joption
4033N/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.
4033N/A.LP
4033N/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.
4033N/A.RE
4033N/A
4033N/A.LP
4033N/A.RE
4033N/A.SH "COMMAND LINE ARGUMENT FILES"
4033N/A.LP
4033N/A
4033N/A.LP
4033N/A.LP
4033N/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.
4033N/A.LP
1178N/A.LP
1178N/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.
1178N/A.LP
1178N/A.LP
4033N/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.
4033N/A.LP
1178N/A.LP
4033N/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.
4033N/A.LP
4033N/A.SS
4033N/AExample \- Single Arg File
4033N/A.LP
4033N/A.LP
4033N/AYou could use a single argument file named "\f2argfile\fP" to hold all javac arguments:
4033N/A.LP
4033N/A.nf
4033N/A\f3
4033N/A.fl
4033N/A % \fP\f3javac @argfile\fP
1178N/A.fl
1178N/A
1178N/A.fl
1178N/A.fi
4033N/A
4033N/A.LP
4033N/A.LP
4033N/AThis argument file could contain the contents of both files shown in the next example.
4033N/A.LP
4033N/A.SS
4033N/AExample \- Two Arg Files
4033N/A.LP
4033N/A.LP
4033N/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.)
4033N/A.LP
4033N/A.LP
4033N/ACreate a file named "\f2options\fP" containing:
4033N/A.LP
4033N/A.nf
4033N/A\f3
4033N/A.fl
4033N/A \-d classes
4033N/A.fl
4033N/A \-g
4033N/A.fl
4033N/A \-sourcepath /java/pubs/ws/1.3/src/share/classes
4033N/A.fl
4033N/A
1178N/A.fl
1178N/A\fP
4935N/A.fi
4033N/A
4033N/A.LP
4033N/A.LP
4033N/ACreate a file named "\f2classes\fP" containing:
4033N/A.LP
4033N/A.nf
4033N/A\f3
4033N/A.fl
4033N/A MyClass1.java
4033N/A.fl
4033N/A MyClass2.java
4033N/A.fl
4033N/A MyClass3.java
4033N/A.fl
4033N/A
4033N/A.fl
4033N/A\fP
4033N/A.fi
4033N/A
4033N/A.LP
4033N/A.LP
4033N/AYou would then run \f3javac\fP with:
4033N/A.LP
4033N/A.nf
4033N/A\f3
4935N/A.fl
4033N/A % \fP\f3javac @options @classes\fP
4033N/A.fl
4935N/A
4033N/A.fl
4033N/A.fi
4033N/A
4033N/A.LP
4033N/A.SS
4935N/AExample \- Arg Files with Paths
4033N/A.LP
4033N/A.LP
4033N/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):
4033N/A.LP
4033N/A.nf
4033N/A\f3
4033N/A.fl
4033N/A % \fP\f3javac @path1/options @path2/classes\fP
4033N/A.fl
4033N/A
4033N/A.fl
4033N/A.fi
4033N/A
4033N/A.LP
4033N/A.SH "ANNOTATION PROCESSING"
4033N/A.LP
4033N/A
4033N/A.LP
4033N/A.LP
4033N/A\f3javac\fP provides direct support for annotation processing, superseding the need for the separate annotation processing tool, \f3apt\fP.
4033N/A.LP
4033N/A.LP
4033N/AThe API for annotation processors is defined in the \f2javax.annotation.processing\fP and \f2javax.lang.model\fP packages and subpackages.
4033N/A.LP
1178N/A.SS
1178N/AOverview of annotation processing
4935N/A.LP
4033N/A.LP
4033N/AUnless annotation processing is disabled with the \f3\-proc:none\fP option, the compiler searches for any annotation processors that are available. The search path can be specified with the \f3\-processorpath\fP option; if it is not given, the user class path is used. Processors are located by means of service provider\-configuration files named
4033N/A.br
4033N/A\f2\ META\-INF/services/javax.annotation.processing.Processor\fP
4033N/A.br
4033N/Aon the search path. Such files should contain the names of any annotation processors to be used, listed one per line. Alternatively, processors can be specified explicitly, using the \f3\-processor\fP option.
4033N/A.LP
4033N/A.LP
4033N/AAfter scanning the source files and classes on the command line to determine what annotations are present, the compiler queries the processors to determine what annotations they process. When a match is found, the processor will be invoked. A processor may "claim" the annotations it processes, in which case no further attempt is made to find any processors for those annotations. Once all annotations have been claimed, the compiler does not look for additional processors.
4033N/A.LP
4935N/A.LP
4033N/AIf any processors generate any new source files, another round of annotation processing will occur: any newly generated source files will be scanned, and the annotations processed as before. Any processors invoked on previous rounds will also be invoked on all subsequent rounds. This continues until no new source files are generated.
4033N/A.LP
4935N/A.LP
4033N/AAfter a round occurs where no new source files are generated, the annotation processors will be invoked one last time, to give them a chance to complete any work they may need to do. Finally, unless the \f3\-proc:only\fP option is used, the compiler will compile the original and all the generated source files.
4033N/A.LP
4033N/A.SS
4033N/AImplicitly loaded source files
4033N/A.LP
4033N/A.LP
4033N/ATo compile a set of source files, the compiler may need to implicitly load additional source files. (See Searching For Types). Such files are currently not subject to annotation processing. By default, the compiler will give a warning if annotation processing has occurred and any implicitly loaded source files are compiled. See the \-implicit option for ways to suppress the warning.
4033N/A.LP
4033N/A.SH "SEARCHING FOR TYPES"
4033N/A.LP
4033N/A
4033N/A.LP
4033N/A.LP
4033N/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.
4033N/A.LP
4033N/A.LP
4033N/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.
4033N/A.LP
4033N/A.LP
4033N/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
4033N/A.na
4935N/A\f2Setting the Class Path\fP @
4033N/A.fi
4033N/Ahttp://java.sun.com/javase/6/docs/technotes/tools/index.html#classpath).
4033N/A.LP
4033N/A.LP
4033N/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.
4935N/A.LP
4033N/A.LP
4033N/AYou can specify different bootstrap or extension classes with the \f3\-bootclasspath\fP and \f3\-extdirs\fP options; see Cross\-Compilation Options below.
4033N/A.LP
4033N/A.LP
4033N/AA successful type search may produce a class file, a source file, or both. If both are found, you can use the \-Xprefer option to instruct the compiler which to use. If \f3newer\fP is given, the compiler will use the newer of the two files. If \f3source\fP is given, it will use the source file. The default is \f3newer\fP.
4033N/A.LP
4033N/A.LP
4033N/AIf a type search finds a source file for a required type, either by itself, or as a result of the setting for \f3\-Xprefer\fP, the compiler will read the source file to get the information it needs. In addition, it will by default compile the source file as well. You can use the \-implicit option to specify the behavior. If \f3none\fP is given, no class files will be generated for the source file. If \f3class\fP is given, class files will be generated for the source file.
4033N/A.LP
1178N/A.LP
4935N/AThe compiler may not discover the need for some type information until after annotation processing is complete. If the type information is found in a source file and no \f3\-implicit\fP option is given, the compiler will give a warning that the file is being compiled without being subject to annotation processing. To disable the warning, either specify the file on the command line (so that it will be subject to annotation processing) or use the \f3\-implicit\fP option to specify whether or not class files should be generated for such source files.
4033N/A.LP
4033N/A.SH "PROGRAMMATIC INTERFACE"
4033N/A.LP
4033N/A
4033N/A.LP
4935N/A.LP
4033N/A\f3javac\fP supports the new Java Compiler API defined by the classes and interfaces in the \f2javax.tools\fP package.
4033N/A.LP
4033N/A.SS
4033N/AExample
4033N/A.LP
4033N/A.LP
4033N/ATo perform a compilation using arguments as you would give on the command line, you can use the following:
4033N/A.LP
4033N/A.nf
4033N/A\f3
4033N/A.fl
4033N/AJavaCompiler javac = ToolProvider.getSystemJavaCompiler();
4033N/A.fl
4033N/Aint rc = javac.run(null, null, null, args);
4033N/A.fl
4033N/A
4935N/A.fl
1178N/A\fP
4033N/A.fi
4033N/A
4033N/A.LP
4033N/A.LP
4033N/AThis will write any diagnostics to the standard output stream, and return the exit code that \f3javac\fP would give when invoked from the command line.
4033N/A.LP
1178N/A.LP
1178N/AYou can use other methods on the \f2javax.tools.JavaCompiler\fP interface to handle diagnostics, control where files are read from and written to, and so on.
4033N/A.LP
4033N/A.SS
4033N/AOld Interface
4033N/A.LP
4033N/A.RS 3
4033N/A
4033N/A.LP
4935N/A.LP
4033N/A\f3Note:\fP \ This API is retained for backwards compatibility only; all new code should use the Java Compiler API, described above.
4033N/A.LP
4033N/A.LP
4033N/AThe \f2com.sun.tools.javac.Main\fP class provides two static methods to invoke the compiler from a program:
4033N/A.LP
4033N/A.nf
4033N/A\f3
4033N/A.fl
4033N/Apublic static int compile(String[] args);
4033N/A.fl
4033N/Apublic static int compile(String[] args, PrintWriter out);
4935N/A.fl
4033N/A
4033N/A.fl
4033N/A\fP
1178N/A.fi
1178N/A
1178N/A.LP
4935N/A.LP
1178N/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.
1178N/A.LP
1178N/A.LP
1178N/AThe \f2out\fP parameter indicates where the compiler's diagnostic output is directed.
1178N/A.LP
1178N/A.LP
1178N/AThe return value is equivalent to the exit value from \f3javac\fP.
1178N/A.LP
1178N/A.LP
4935N/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.
1178N/A.LP
1178N/A.RE
4935N/A.SH "EXAMPLES"
1178N/A.LP
1178N/A.SS
4935N/ACompiling a Simple Program
1178N/A.LP
1178N/A.RS 3
4033N/A
1178N/A.LP
1178N/A.LP
4033N/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.
1178N/A.LP
1178N/A.RS 3
4935N/A
1178N/A.LP
1178N/A.nf
4935N/A\f3
1178N/A.fl
1178N/A% \fP\f3ls\fP
4935N/A.fl
4935N/Agreetings/
4935N/A.fl
4935N/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
4033N/A
0N/A.fl
0N/Apublic class Hello {
0N/A.fl
4935N/A public static void main(String[] args) {
0N/A.fl
4935N/A for (int i=0; i < args.length; i++) {
0N/A.fl
4935N/A System.out.println("Hello " + args[i]);
0N/A.fl
4935N/A }
0N/A.fl
0N/A }
0N/A.fl
4033N/A}
0N/A.fl
0N/A% \f3javac greetings/Hello.java\fP
1178N/A.fl
0N/A% \f3ls greetings\fP
0N/A.fl
1178N/AHello.class Hello.java
4935N/A.fl
0N/A% \f3java greetings.Hello World Universe Everyone\fP
4935N/A.fl
1178N/AHello World
1178N/A.fl
4935N/AHello Universe
1178N/A.fl
0N/AHello Everyone
1178N/A.fl
4935N/A
0N/A.fl
1178N/A.fi
4935N/A.RE
0N/A
1178N/A.LP
1178N/A.RE
4935N/A.SS
1178N/ACompiling Multiple Source Files
1178N/A.LP
4935N/A.RS 3
1178N/A
1178N/A.LP
1178N/A.LP
4935N/AThis example compiles all the source files in the package \f2greetings\fP.
0N/A.LP
1178N/A.RS 3
4935N/A
1178N/A.LP
1178N/A.nf
4935N/A\f3
4033N/A.fl
1178N/A% \fP\f3ls\fP
1178N/A.fl
4033N/Agreetings/
1178N/A.fl
1178N/A% \f3ls greetings\fP
1178N/A.fl
4935N/AAloha.java GutenTag.java Hello.java Hi.java
4935N/A.fl
4935N/A% \f3javac greetings/*.java\fP
4033N/A.fl
0N/A% \f3ls greetings\fP
0N/A.fl
0N/AAloha.class GutenTag.class Hello.class Hi.class
1178N/A.fl
4935N/AAloha.java GutenTag.java Hello.java Hi.java
1178N/A.fl
1178N/A
4935N/A.fl
1178N/A
1178N/A.fl
1178N/A.fi
4033N/A.RE
1178N/A
1178N/A.LP
1178N/A.RE
1178N/A.SS
4935N/ASpecifying a User Class Path
0N/A.LP
0N/A.RS 3
0N/A
0N/A.LP
.LP
Having changed one of the source files in the previous example, we recompile it:
.LP
.RS 3
.LP
.nf
\f3
.fl
% \fP\f3pwd\fP
.fl
/examples
.fl
% \f3javac greetings/Hi.java\fP
.fl
.fl
.fi
.RE
.LP
.LP
Since \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.
.LP
.RS 3
.LP
.nf
\f3
.fl
% \fP\f3javac \-classpath /examples /examples/greetings/Hi.java\fP
.fl
.fl
.fi
.RE
.LP
.LP
If we change \f2greetings.Hi\fP again, to use a banner utility, that utility also needs to be accessible through the user class path.
.LP
.RS 3
.LP
.nf
\f3
.fl
% \fP\f3javac \-classpath /examples:/lib/Banners.jar \\
.fl
/examples/greetings/Hi.java\fP
.fl
.fl
.fi
.RE
.LP
.LP
To execute a class in \f2greetings\fP, we need access both to \f2greetings\fP and to the classes it uses.
.LP
.RS 3
.LP
.nf
\f3
.fl
% \fP\f3java \-classpath /examples:/lib/Banners.jar greetings.Hi\fP
.fl
.fl
.fi
.RE
.LP
.RE
.SS
Separating Source Files and Class Files
.LP
.RS 3
.LP
.LP
It 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.
.LP
.RS 3
.LP
.nf
\f3
.fl
% \fP\f3ls\fP
.fl
classes/ lib/ src/
.fl
% \f3ls src\fP
.fl
farewells/
.fl
% \f3ls src/farewells\fP
.fl
Base.java GoodBye.java
.fl
% \f3ls lib\fP
.fl
Banners.jar
.fl
% \f3ls classes\fP
.fl
% \f3javac \-sourcepath src \-classpath classes:lib/Banners.jar \\
.fl
src/farewells/GoodBye.java \-d classes\fP
.fl
% \f3ls classes\fP
.fl
farewells/
.fl
% \f3ls classes/farewells\fP
.fl
Base.class GoodBye.class
.fl
.fl
.fl
.fi
.RE
.LP
.LP
\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.
.LP
.RE
.SS
Cross\-Compilation Example
.LP
.RS 3
.LP
.LP
Here we use \f3javac\fP to compile code that will run on a 1.7 VM.
.LP
.RS 3
.LP
.nf
\f3
.fl
% \fP\f3javac \-target 1.7 \-bootclasspath jdk1.7.0/lib/rt.jar \\
.fl
\-extdirs "" OldCode.java\fP
.fl
.fl
.fi
.RE
.LP
.LP
The \f3\-target 1.7\fP option ensures that the generated class files will be compatible with 1.7 VMs. By default, \f3javac\fP compiles for JDK 6.
.LP
.LP
The 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.7 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.7 VM and would fail at runtime.
.LP
.RE
.SH "SEE ALSO"
.LP
.LP
.RS 3
.TP 2
o
.na
\f2The javac Guide\fP @
.fi
http://java.sun.com/javase/6/docs/technotes/guides/javac/index.html
.TP 2
o
java(1) \- the Java Application Launcher
.TP 2
o
jdb(1) \- Java Application Debugger
.TP 2
o
javah(1) \- C Header and Stub File Generator
.TP 2
o
javap(1) \- Class File Disassembler
.TP 2
o
javadoc(1) \- API Documentation Generator
.TP 2
o
jar(1) \- JAR Archive Tool
.TP 2
o
.na
\f2The Java Extensions Framework\fP @
.fi
http://java.sun.com/javase/6/docs/technotes/guides/extensions/index.html
.RE
.LP
.LP