Copyright (c) 1994, 2015, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation.
This code is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
Arch: generic
Software: JDK 8
Date: 03 March 2015
SectDesc: Basic Tools
Title: javac.1
* Define some portability stuff
-----------------------------------------------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
http://bugs.debian.org/507673
http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-----------------------------------------------------------------
* set default formatting
-----------------------------------------------------------------
disable hyphenation
disable justification (adjust text to left margin only)
-----------------------------------------------------------------
* MAIN CONTENT STARTS HERE *
-----------------------------------------------------------------
javac [ options ] [ sourcefiles ] [ classes] [ @argfiles ]Arguments can be in any order:
options Command-line options. See Options.
sourcefiles One or more source files to be compiled (such as \f3MyClass.java).
classes One or more classes to be processed for annotations (such as \f3MyPackage.MyClass).
@argfiles One or more files that list options and source files. The \f3-J options are not allowed in these files. See Command-Line Argument Files.
There are two ways to pass source code file names to \f3javac.
0.2i For a small number of source files, list the file names on the command line.
0.2i For a large number of source files, list the file names in a file that is separated by blanks or line breaks. Use the list file name preceded by an at sign (@) with the \f3javac command.
Source code file names must have .java suffixes, class file names must have .class suffixes, and both source and class files must have root names that identify the class. For example, a class called \f3MyClass would be written in a source file called \f3MyClass.java and compiled into a bytecode class file called \f3MyClass.class.
Inner class definitions produce additional class files. These class files have names that combine the inner and outer class names, such as \f3MyClass$MyInnerClass.class.
Arrange source files in a directory tree that reflects their package tree. For example, if all of your source files are in \f3/workspace, then put the source code for \f3com.mysoft.mypack.MyClass in \f3/workspace/com/mysoft/mypack/MyClass.java.
By default, the compiler puts each class file in the same directory as its source file. You can specify a separate destination directory with the \f3-d option.
0.2i See also Cross-Compilation Options
0.2i See also Nonstandard Options
-Akey[=value]
Specifies options to pass to annotation processors. These options are not interpreted by \f3javac directly, but are made available for use by individual processors. The \f3key value should be one or more identifiers separated by a dot (.).
-cp path or -classpath path
Specifies where to find user class files, and (optionally) annotation processors and source files. This class path overrides the user class path in the \f3CLASSPATH environment variable. If neither \f3CLASSPATH, \f3-cp nor \f3-classpath is specified, then the user class path is the current directory. See Setting the Class Path. If the \f3-sourcepath option is not specified, then the user class path is also searched for source files. If the \f3-processorpath option is not specified, then the class path is also searched for annotation processors.
-Djava.ext.dirs=directories
Overrides the location of installed extensions.
-Djava.endorsed.dirs=directories
Overrides the location of the endorsed standards path.
-d directory
Sets the destination directory for class files. The directory must already exist because \f3javac does not create it. If a class is part of a package, then \f3javac puts the class file in a subdirectory that reflects the package name and creates directories as needed. If you specify \f3-d\f3/home/myclasses and the class is called \f3com.mypackage.MyClass, then the class file is \f3/home/myclasses/com/mypackage/MyClass.class. If the -d option is not specified, then \f3javac puts each class file in the same directory as the source file from which it was generated. Note: The directory specified by the -d option is not automatically added to your user class path.
-deprecation
Shows a description of each use or override of a deprecated member or class. Without the \f3-deprecation option, \f3javac shows a summary of the source files that use or override deprecated members or classes. The \f3-deprecation option is shorthand for \f3-Xlint:deprecation.
-encoding encoding
Sets the source file encoding name, such as EUC-JP and UTF-8. If the \f3-encoding option is not specified, then the platform default converter is used.
-endorseddirs directories
Overrides the location of the endorsed standards path.
-extdirs directories
Overrides the location of the \f3ext directory. The directories variable is a colon-separated list of directories. Each JAR file in the specified directories is searched for class files. All JAR files found become part of the class path. If you are cross-compiling (compiling classes against bootstrap and extension classes of a different Java platform implementation), then this option specifies the directories that contain the extension classes. See Cross-Compilation Options for more information.
-g
Generates all debugging information, including local variables. By default, only line number and source file information is generated.
-g:none
Does not generate any debugging information.
-g:[keyword list]
Generates only some kinds of debugging information, specified by a comma separated list of keywords. Valid keywords are:
source Source file debugging information.
lines Line number debugging information.
vars Local variable debugging information.
-help
Prints a synopsis of standard options.
-implicit:[class, none]
Controls the generation of class files for implicitly loaded source files. To automatically generate class files, use \f3-implicit:class. To suppress class file generation, use \f3-implicit:none. If this option is not specified, then the default is to automatically generate class files. In this case, the compiler issues a warning if any such class files are generated when also doing annotation processing. The warning is not issued when the \f3-implicit option is set explicitly. See Searching for Types.
-Joption
Passes \f3option to the Java Virtual Machine (JVM), where option is one of the options described on the reference page for the Java launcher. For example, \f3-J-Xms48m sets the startup memory to 48 MB. See java(1). Note: The CLASSPATH, \f3-classpath, \f3-bootclasspath, and \f3-extdirs options do not specify the classes used to run \f3javac. Trying to customize the compiler implementation with these options and variables is risky and often does not accomplish what you want. If you must customize the complier implementation, then use the \f3-J option to pass options through to the underlying \f3Java launcher.
-nowarn
Disables warning messages. This option operates the same as the \f3-Xlint:none option.
-parameters
Stores formal parameter names of constructors and methods in the generated class file so that the method \f3java.lang.reflect.Executable.getParameters from the Reflection API can retrieve them.
-proc: [none, only]
Controls whether annotation processing and compilation are done. \f3-proc:none means that compilation takes place without annotation processing. \f3-proc:only means that only annotation processing is done, without any subsequent compilation.
-processor class1 [,class2,class3...]
Names of the annotation processors to run. This bypasses the default discovery process.
-processorpath path
Specifies where to find annotation processors. If this option is not used, then the class path is searched for processors.
-s dir
Specifies the directory where to place the generated source files. The directory must already exist because \f3javac does not create it. If a class is part of a package, then the compiler puts the source file in a subdirectory that reflects the package name and creates directories as needed. If you specify \f3-s /home/mysrc and the class is called \f3com.mypackage.MyClass, then the source file is put in \f3/home/mysrc/com/mypackage/MyClass.java.
-source release
Specifies the version of source code accepted. The following values for \f3release are allowed:
1.3 The compiler does not support assertions, generics, or other language features introduced after Java SE 1.3.
1.4 The compiler accepts code containing assertions, which were introduced in Java SE 1.4.
1.5 The compiler accepts code containing generics and other language features introduced in Java SE 5.
5 Synonym for 1.5.
1.6 No language changes were introduced in Java SE 6. However, encoding errors in source files are now reported as errors instead of warnings as in earlier releases of Java Platform, Standard Edition.
6 Synonym for 1.6.
1.7 The compiler accepts code with features introduced in Java SE 7.
7 Synonym for 1.7.
1.8 This is the default value. The compiler accepts code with features introduced in Java SE 8.
8 Synonym for 1.8.
-sourcepath sourcepath
Specifies the source code path to search for class or interface definitions. As with the user class path, source path entries are separated by colons (:) on Oracle Solaris and semicolons on Windows and can be directories, JAR archives, or ZIP archives. If packages are used, then the local path name within the directory or archive must reflect the package name. Note: Classes found through the class path might be recompiled when their source files are also found. See Searching for Types.
-verbose
Uses verbose output, which includes information about each class loaded and each source file compiled.
-version
Prints release information.
-werror
Terminates compilation when warnings occur.
-X
Displays information about nonstandard options and exits.
-target version
Generates class files that target a specified release of the virtual machine. Class files will run on the specified target and on later releases, but not on earlier releases of the JVM. Valid targets are 1.1, 1.2, 1.3, 1.4, 1.5 (also 5), 1.6 (also 6), 1.7 (also 7), and 1.8 (also 8). The default for the \f3-target option depends on the value of the \f3-source option:
0.2i If the \f3-source option is not specified, then the value of the \f3-target option is 1.8
0.2i If the \f3-source option is 1.2, then the value of the \f3-target option is 1.4
0.2i If the \f3-source option is 1.3, then the value of the \f3-target option is 1.4
0.2i If the \f3-source option is 1.5, then the value of the \f3-target option is 1.8
0.2i If the \f3-source option is 1.6, then the value of the \f3-target is option 1.8
0.2i If the \f3-source option is 1.7, then the value of the \f3-target is option 1.8
0.2i For all other values of the \f3-source option, the value of the \f3-target option is the value of the \f3-source option.
-bootclasspath bootclasspath
Cross-compiles against the specified set of boot classes. As with the user class path, boot class path entries are separated by colons (:) and can be directories, JAR archives, or ZIP archives.
The supported profile values are \f3compact1, \f3compact2, and \f3compact3. These are additive layers. Each higher-numbered compact profile contains all of the APIs in profiles with smaller number names.
-profile
When using compact profiles, this option specifies the profile name when compiling. For example:
\f3javac -profile compact1 Hello.java
\f3javac does not compile source code that uses any Java SE APIs that is not in the specified profile. Here is an example of the error message that results from attempting to compile such source code:
\f3cd jdk1.8.0/bin
\f3./javac -profile compact1 Paint.java
\f3Paint.java:5: error: Applet is not available in profile 'compact1'
\f3import java.applet.Applet;
\f3In this example, you can correct the error by modifying the source to not use the \f3Applet class. You could also correct the error by compiling without the -profile option. Then the compilation would be run against the full set of Java SE APIs. (None of the compact profiles include the \f3Applet class.) An alternative way to compile with compact profiles is to use the \f3-bootclasspath option to specify a path to an \f3rt.jar file that specifies a profile's image. Using the \f3-profile option instead does not require a profile image to be present on the system at compile time. This is useful when cross-compiling.
-Xbootclasspath/p:path
Adds a suffix to the bootstrap class path.
-Xbootclasspath/a:path
Adds a prefix to the bootstrap class path.
-Xbootclasspath/:path
Overrides the location of the bootstrap class files.
-Xdoclint:[-]group [/access]
Enables or disables specific groups of checks, where group is one of the following values: \f3accessibility, \f3syntax, \f3reference, \f3html or \f3missing. For more information about these groups of checks see the \f3-Xdoclint option of the \f3javadoc command. The \f3-Xdoclint option is disabled by default in the \f3javac command. The variable access specifies the minimum visibility level of classes and members that the \f3-Xdoclint option checks. It can have one of the following values (in order of most to least visible) : \f3public, \f3protected, \f3package and \f3private. For example, the following option checks classes and members (with all groups of checks) that have the access level protected and higher (which includes protected, package and public):
\f3-Xdoclint:all/protected
\f3The following option enables all groups of checks for all access levels, except it will not check for HTML errors for classes and members that have access level package and higher (which includes package and public):
\f3-Xdoclint:all,-html/package
\f3
-Xdoclint:none
Disables all groups of checks.
-Xdoclint:all[/access]
Enables all groups of checks.
-Xlint
Enables all recommended warnings. In this release, enabling all available warnings is recommended.
-Xlint:all
Enables all recommended warnings. In this release, enabling all available warnings is recommended.
-Xlint:none
Disables all warnings.
-Xlint:name
Disables warning name. See Enable or Disable Warnings with the -Xlint Option for a list of warnings you can disable with this option.
-Xlint:-name
Disables warning name. See Enable or Disable Warnings with the -Xlint Option with the \f3-Xlint option to get a list of warnings that you can disable with this option.
-Xmaxerrs number
Sets the maximum number of errors to print.
-Xmaxwarns number
Sets the maximum number of warnings to print.
-Xstdout filename
Sends compiler messages to the named file. By default, compiler messages go to \f3System.err.
-Xprefer:[newer,source]
Specifies which file to read when both a source file and class file are found for a type. (See Searching for Types). If the \f3-Xprefer:newer option is used, then it reads the newer of the source or class file for a type (default). If the \f3-Xprefer:source option is used, then it reads the source file. Use -\f3Xprefer:source when you want to be sure that any annotation processors can access annotations declared with a retention policy of \f3SOURCE.
-Xpkginfo:[always,legacy,nonempty]
Control whether javac generates \f3package-info.class files from package-info.java files. Possible mode arguments for this option include the following.
always Always generate a \f3package-info.class file for every \f3package-info.java file. This option may be useful if you use a build system such as Ant, which checks that each \f3.java file has a corresponding \f3.class file.
legacy Generate a \f3package-info.class file only if package-info.java contains annotations. Don't generate a \f3package-info.class file if package-info.java only contains comments. Note: A \f3package-info.class file might be generated but be empty if all the annotations in the package-info.java file have \f3RetentionPolicy.SOURCE.
nonempty Generate a \f3package-info.class file only if package-info.java contains annotations with \f3RetentionPolicy.CLASS or \f3RetentionPolicy.RUNTIME.
-Xprint
Prints a textual representation of specified types for debugging purposes. Perform neither annotation processing nor compilation. The format of the output could change.
-XprintProcessorInfo
Prints information about which annotations a processor is asked to process.
-XprintRounds
Prints information about initial and subsequent annotation processing rounds.
cast Warns about unnecessary and redundant casts, for example:
\f3String s = (String) "Hello!"
\f3
classfile Warns about issues related to class file contents.
deprecation Warns about the use of deprecated items, for example:
\f3java.util.Date myDate = new java.util.Date();
\f3int currentDay = myDate.getDay();
\f3The method \f3java.util.Date.getDay has been deprecated since JDK 1.1
dep-ann Warns about items that are documented with an \f3@deprecated Javadoc comment, but do not have a \f3@Deprecated annotation, for example:
\f3/**
\f3 * @deprecated As of Java SE 7, replaced by {@link #newMethod()}
\f3 */
\f3public static void deprecatedMethood() { }
\f3public static void newMethod() { }
\f3
divzero Warns about division by the constant integer 0, for example:
\f3int divideByZero = 42 / 0;
\f3
empty Warns about empty statements after \f3ifstatements, for example:
\f3class E {
\f3 void m() {
\f3 if (true) ;
\f3 }
\f3}
\f3
fallthrough Checks the switch blocks for fall-through cases and provides a warning message for any that are found. Fall-through cases are cases in a switch block, other than the last case in the block, whose code does not include a break statement, allowing code execution to fall through from that case to the next case. For example, the code following the case 1 label in this switch block does not end with a break statement:
\f3switch (x) {
\f3case 1:
\f3 System.out.println("1");
\f3 // No break statement here.
\f3case 2:
\f3 System.out.println("2");
\f3}
\f3If the \f3-Xlint:fallthrough option was used when compiling this code, then the compiler emits a warning about possible fall-through into case, with the line number of the case in question.
finally Warns about \f3finally clauses that cannot complete normally, for example:
\f3public static int m() {
\f3 try {
\f3 throw new NullPointerException();
\f3 } catch (NullPointerException(); {
\f3 System.err.println("Caught NullPointerException.");
\f3 return 1;
\f3 } finally {
\f3 return 0;
\f3 }
\f3 }
\f3The compiler generates a warning for the \f3finally block in this example. When the \f3int method is called, it returns a value of 0. A \f3finally block executes when the \f3try block exits. In this example, when control is transferred to the \f3catch block, the \f3int method exits. However, the \f3finally block must execute, so it is executed, even though control was transferred outside the method.
options Warns about issues that related to the use of command-line options. See Cross-Compilation Options.
overrides Warns about issues regarding method overrides. For example, consider the following two classes:
\f3public class ClassWithVarargsMethod {
\f3 void varargsMethod(String... s) { }
\f3}
\f3
\f3public class ClassWithOverridingMethod extends ClassWithVarargsMethod {
\f3 @Override
\f3 void varargsMethod(String[] s) { }
\f3}
\f3The compiler generates a warning similar to the following:.
\f3warning: [override] varargsMethod(String[]) in ClassWithOverridingMethod
\f3overrides varargsMethod(String...) in ClassWithVarargsMethod; overriding
\f3method is missing '...'
\f3When the compiler encounters a \f3varargs method, it translates the \f3varargs formal parameter into an array. In the method \f3ClassWithVarargsMethod.varargsMethod, the compiler translates the \f3varargs formal parameter \f3String... s to the formal parameter \f3String[] s, an array, which matches the formal parameter of the method \f3ClassWithOverridingMethod.varargsMethod. Consequently, this example compiles.
path Warns about invalid path elements and nonexistent path directories on the command line (with regard to the class path, the source path, and other paths). Such warnings cannot be suppressed with the \f3@SuppressWarnings annotation, for example:
\f3javac -Xlint:path -classpath /nonexistentpath Example.java
\f3
processing Warn about issues regarding annotation processing. The compiler generates this warning when you have a class that has an annotation, and you use an annotation processor that cannot handle that type of exception. For example, the following is a simple annotation processor: Source file AnnocProc.java:
\f3import java.util.*;
\f3import javax.annotation.processing.*;
\f3import javax.lang.model.*;
\f3import.javaz.lang.model.element.*;
\f3
\f3@SupportedAnnotationTypes("NotAnno")
\f3public class AnnoProc extends AbstractProcessor {
\f3 public boolean process(Set<? extends TypeElement> elems, RoundEnvironment renv){
\f3 return true;
\f3 }
\f3
\f3 public SourceVersion getSupportedSourceVersion() {
\f3 return SourceVersion.latest();
\f3 }
\f3}
\f3Source file AnnosWithoutProcessors.java:
\f3@interface Anno { }
\f3
\f3@Anno
\f3class AnnosWithoutProcessors { }
\f3The following commands compile the annotation processor \f3AnnoProc, then run this annotation processor against the source file \f3AnnosWithoutProcessors.java:
\f3javac AnnoProc.java
\f3javac -cp . -Xlint:processing -processor AnnoProc -proc:only AnnosWithoutProcessors.java
\f3When the compiler runs the annotation processor against the source file \f3AnnosWithoutProcessors.java, it generates the following warning:
\f3warning: [processing] No processor claimed any of these annotations: Anno
\f3To resolve this issue, you can rename the annotation defined and used in the class \f3AnnosWithoutProcessors from \f3Anno to \f3NotAnno.
rawtypes Warns about unchecked operations on raw types. The following statement generates a \f3rawtypes warning:
\f3void countElements(List l) { ... }
\f3The following example does not generate a \f3rawtypes warning
\f3void countElements(List<?> l) { ... }
\f3\f3List is a raw type. However, \f3List<?> is an unbounded wildcard parameterized type. Because \f3List is a parameterized interface, always specify its type argument. In this example, the \f3List formal argument is specified with an unbounded wildcard (\f3?) as its formal type parameter, which means that the \f3countElements method can accept any instantiation of the \f3List interface.
Serial Warns about missing \f3serialVersionUID definitions on serializable classes, for example:
\f3public class PersistentTime implements Serializable
\f3{
\f3 private Date time;
\f3
\f3 public PersistentTime() {
\f3 time = Calendar.getInstance().getTime();
\f3 }
\f3
\f3 public Date getTime() {
\f3 return time;
\f3 }
\f3}
\f3The compiler generates the following warning:
\f3warning: [serial] serializable class PersistentTime has no definition of
\f3serialVersionUID
\f3If a serializable class does not explicitly declare a field named \f3serialVersionUID, then the serialization runtime environment calculates a default \f3serialVersionUID value for that class based on various aspects of the class, as described in the Java Object Serialization Specification. However, it is strongly recommended that all serializable classes explicitly declare \f3serialVersionUID values because the default process of computing \f3serialVersionUID vales is highly sensitive to class details that can vary depending on compiler implementations, and as a result, might cause an unexpected \f3InvalidClassExceptions during deserialization. To guarantee a consistent \f3serialVersionUID value across different Java compiler implementations, a serializable class must declare an explicit \f3serialVersionUID value.
static Warns about issues relating to the use of statics, for example:
\f3class XLintStatic {
\f3 static void m1() { }
\f3 void m2() { this.m1(); }
\f3}
\f3The compiler generates the following warning:
\f3warning: [static] static method should be qualified by type name,
\f3XLintStatic, instead of by an expression
\f3To resolve this issue, you can call the \f3static method \f3m1 as follows:
\f3XLintStatic.m1();
\f3Alternately, you can remove the \f3static keyword from the declaration of the method \f3m1.
try Warns about issues relating to use of \f3try blocks, including try-with-resources statements. For example, a warning is generated for the following statement because the resource \f3ac declared in the \f3try block is not used:
\f3try ( AutoCloseable ac = getResource() ) { // do nothing}
\f3
unchecked Gives more detail for unchecked conversion warnings that are mandated by the Java Language Specification, for example:
\f3List l = new ArrayList<Number>();
\f3List<String> ls = l; // unchecked warning
\f3During type erasure, the types \f3ArrayList<Number> and \f3List<String> become \f3ArrayList and \f3List, respectively. The \f3ls command has the parameterized type \f3List<String>. When the \f3List referenced by \f3l is assigned to \f3ls, the compiler generates an unchecked warning. At compile time, the compiler and JVM cannot determine whether \f3l refers to a \f3List<String> type. In this case, \f3l does not refer to a \f3List<String> type. As a result, heap pollution occurs. A heap pollution situation occurs when the \f3List object \f3l, whose static type is \f3List<Number>, is assigned to another \f3List object, \f3ls, that has a different static type, \f3List<String>. However, the compiler still allows this assignment. It must allow this assignment to preserve backward compatibility with releases of Java SE that do not support generics. Because of type erasure, \f3List<Number> and \f3List<String> both become \f3List. Consequently, the compiler allows the assignment of the object \f3l\f3, which has a raw type of \f3List, to the object \f3ls.
varargs Warns about unsafe usages of variable arguments (\f3varargs) methods, in particular, those that contain non-reifiable arguments, for example:
\f3public class ArrayBuilder {
\f3 public static <T> void addToList (List<T> listArg, T... elements) {
\f3 for (T x : elements) {
\f3 listArg.add(x);
\f3 }
\f3 }
\f3}
\f3Note: A non-reifiable type is a type whose type information is not fully available at runtime. The compiler generates the following warning for the definition of the method \f3ArrayBuilder.addToList
\f3warning: [varargs] Possible heap pollution from parameterized vararg type T
\f3When the compiler encounters a varargs method, it translates the \f3varargs formal parameter into an array. However, the Java programming language does not permit the creation of arrays of parameterized types. In the method \f3ArrayBuilder.addToList, the compiler translates the \f3varargs formal parameter \f3T... elements to the formal parameter \f3T[] elements, an array. However, because of type erasure, the compiler converts the \f3varargs formal parameter to \f3Object[] elements. Consequently, there is a possibility of heap pollution.
An argument file can include \f3javac options and source file names in any combination. The arguments within a file can be separated by spaces or new line characters. If a file name contains embedded spaces, then put the whole file name in double quotation marks.
File Names within an argument file are relative to the current directory, not the location of the argument file. Wild cards (*) are not allowed in these lists (such as for specifying \f3*.java). Use of the at sign (@) to recursively interpret files is not supported. The \f3-J options are not supported because they are passed to the launcher, which does not support argument files.
When executing the \f3javac command, pass in the path and name of each argument file with the at sign (@) leading character. When the \f3javac command encounters an argument beginning with the at sign (@), it expands the contents of that file into the argument list.
\f3Example 1 Single Argument File
You could use a single argument file named \f3argfile to hold all \f3javac arguments:
\f3javac @argfile
\f3This argument file could contain the contents of both files shown in Example 2
\f3Example 2 Two Argument Files
You can create two argument files: one for the \f3javac options and the other for the source file names. Note that the following lists have no line-continuation characters.
Create a file named options that contains the following:
\f3-d classes
\f3-g
\f3-sourcepath /java/pubs/ws/1.3/src/share/classes
\f3Create a file named classes that contains the following:
\f3MyClass1.java
\f3MyClass2.java
\f3MyClass3.java
\f3Then, run the \f3javac command as follows:
\f3javac @options @classes
\f3\f3Example 3 Argument Files with Paths
The argument files can have paths, but any file names inside the files are relative to the current working directory (not \f3path1 or \f3path2):
\f3javac @path1/options @path2/classes
\f3
The API for annotation processors is defined in the \f3javax.annotation.processing and j\f3avax.lang.model packages and subpackages.
After 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 is called. A processor can claim the annotations it processes, in which case no further attempt is made to find any processors for those annotations. After all of the annotations are claimed, the compiler does not search for additional processors.
If any processors generate new source files, then another round of annotation processing occurs: Any newly generated source files are scanned, and the annotations processed as before. Any processors called on previous rounds are also called on all subsequent rounds. This continues until no new source files are generated.
After a round occurs where no new source files are generated, the annotation processors are called one last time, to give them a chance to complete any remaining work. Finally, unless the \f3-proc:only option is used, the compiler compiles the original and all generated source files.
For example, when you create a subclass \f3java.applet.Applet, you are also using the ancestor classes of \f3Applet: \f3java.awt.Panel, \f3java.awt.Container, \f3java.awt.Component, and \f3java.lang.Object.
When the compiler needs type information, it searches for a source file or class file that 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 environment variable or by using the \f3-classpath option.
If you set the \f3-sourcepath option, then the compiler searches the indicated path for source files. Otherwise, the compiler searches the user class path for both class files and source files.
You can specify different bootstrap or extension classes with the \f3-bootclasspath and the \f3-extdirs options. See Cross-Compilation Options.
A successful type search may produce a class file, a source file, or both. If both are found, then you can use the \f3-Xprefer option to instruct the compiler which to use. If \f3newer is specified, then the compiler uses the newer of the two files. If \f3source is specified, the compiler uses the source file. The default is \f3newer.
If a type search finds a source file for a required type, either by itself, or as a result of the setting for the \f3-Xprefer option, then the compiler reads the source file to get the information it needs. By default the compiler also compiles the source file. You can use the \f3-implicit option to specify the behavior. If \f3none is specified, then no class files are generated for the source file. If \f3class is specified, then class files are generated for the source file.
The compiler might not discover the need for some type information until after annotation processing completes. When the type information is found in a source file and no \f3-implicit option is specified, the compiler gives 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 option to specify whether or not class files should be generated for such source files.
\f3JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
\f3The example writes diagnostics to the standard output stream and returns the exit code that \f3javac would give when called from the command line.
You can use other methods in the \f3javax.tools.JavaCompiler interface to handle diagnostics, control where files are read from and written to, and more.
The \f3com.sun.tools.javac.Main class provides two static methods to call the compiler from a program:
\f3public static int compile(String[] args);
\f3public static int compile(String[] args, PrintWriter out);
\f3The \f3args parameter represents any of the command-line arguments that would typically be passed to the compiler.
The \f3out parameter indicates where the compiler diagnostic output is directed.
The \f3return value is equivalent to the \f3exit value from \f3javac.
Note: All other classes and methods found in a package with names that start with \f3com.sun.tools.javac (subpackages of \f3com.sun.tools.javac) are strictly internal and subject to change at any time.
This example shows how to compile the \f3Hello.java source file in the greetings directory. The class defined in \f3Hello.java is called \f3greetings.Hello. The greetings directory is the package directory both for the source file and the class file and is underneath the current directory. This makes it possible to use the default user class path. It also makes it unnecessary to specify a separate destination directory with the \f3-d option.
The source code in \f3Hello.java:
\f3package greetings;
\f3
\f3public class Hello {
\f3 public static void main(String[] args) {
\f3 for (int i=0; i < args.length; i++) {
\f3 System.out.println("Hello " + args[i]);
\f3 }
\f3 }
\f3}
\f3Compile greetings.Hello:
\f3javac greetings/Hello.java
\f3Run \f3greetings.Hello:
\f3java greetings.Hello World Universe Everyone
\f3Hello World
\f3Hello Universe
\f3Hello Everyone
\f3\f3Example 2 Compile Multiple Source Files
This example compiles the \f3Aloha.java, \f3GutenTag.java, \f3Hello.java, and \f3Hi.java source files in the \f3greetings package.
\f3% javac greetings/*.java
\f3% ls greetings
\f3Aloha.class GutenTag.class Hello.class Hi.class
\f3Aloha.java GutenTag.java Hello.java Hi.java
\f3\f3Example 3 Specify a User Class Path
After changing one of the source files in the previous example, recompile it:
\f3pwd
\f3/examples
\f3javac greetings/Hi.java
\f3Because \f3greetings.Hi refers to other classes in the \f3greetings package, the compiler needs to find these other classes. The previous example works because the default user class path is the directory that contains the package directory. If you want to recompile this file without concern for which directory you are in, then add the examples directory to the user class path by setting \f3CLASSPATH. This example uses the \f3-classpath option.
\f3javac -classpath /examples /examples/greetings/Hi.java
\f3If you change \f3greetings.Hi to use a banner utility, then that utility also needs to be accessible through the user class path.
\f3javac -classpath /examples:/lib/Banners.jar \e
\f3 /examples/greetings/Hi.java
\f3To execute a class in the \f3greetings package, the program needs access to the \f3greetings package, and to the classes that the \f3greetings classes use.
\f3java -classpath /examples:/lib/Banners.jar greetings.Hi
\f3\f3Example 4 Separate Source Files and Class Files
The following example uses \f3javac to compile code that runs on JVM 1.7.
\f3javac -source 1.7 -target 1.7 -bootclasspath jdk1.7.0/lib/rt.jar \e
\f3-extdirs "" OldCode.java
\f3The \f3-source 1.7 option specifies that release 1.7 (or 7) of the Java programming language be used to compile \f3OldCode.java. The option \f3-target 1.7 option ensures that the generated class files are compatible with JVM 1.7. Note that in most cases, the value of the \f3-target option is the value of the \f3-source option; in this example, you can omit the \f3-target option.
You must specify the \f3-bootclasspath option to specify the correct version of the bootstrap classes (the \f3rt.jar library). If not, then the compiler generates a warning:
\f3javac -source 1.7 OldCode.java
\f3warning: [options] bootstrap class path not set in conjunction with
\f3-source 1.7
\f3If you do not specify the correct version of bootstrap classes, then the compiler uses the old language rules (in this example, it uses version 1.7 of the Java programming language) combined with the new bootstrap classes, which can result in class files that do not work on the older platform (in this case, Java SE 7) because reference to nonexistent methods can get included.
\f3Example 5 Cross Compile
This example uses \f3javac to compile code that runs on JVM 1.7.
\f3javac -source 1.7 -target 1.7 -bootclasspath jdk1.7.0/lib/rt.jar \e
\f3 -extdirs "" OldCode.java
\f3The\f3-source 1.7 option specifies that release 1.7 (or 7) of the Java programming language to be used to compile OldCode.java. The \f3-target 1.7 option ensures that the generated class files are compatible with JVM 1.7.
You must specify the \f3-bootclasspath option to specify the correct version of the bootstrap classes (the \f3rt.jar library). If not, then the compiler generates a warning:
\f3javac -source 1.7 OldCode.java
\f3warning: [options] bootstrap class path not set in conjunction with -source 1.7
\f3If you do not specify the correct version of bootstrap classes, then the compiler uses the old language rules combined with the new bootstrap classes. This combination can result in class files that do not work on the older platform (in this case, Java SE 7) because reference to nonexistent methods can get included. In this example, the compiler uses release 1.7 of the Java programming language.
0.2i java(1)
0.2i jdb(1)
0.2i javah(1)
0.2i javadoc(1)
0.2i jar(1)
0.2i jdb(1)
'pl 8.5i 'bp