Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are used
-classpath <path> Specify where to find user class files and annotation processors
-cp <path> Specify where to find user class files and annotation processors
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-endorseddirs <dirs> Override location of endorsed standards path
-proc:{none,only} Control whether annotation processing and/or compilation is done.
-processor <class1>[,<class2>,<class3>...] Names of the annotation processors to run; bypasses default discovery process
-processorpath <path> Specify where to find annotation processors
-parameters Generate metadata for reflection on method parameters
-d <directory> Specify where to place generated class files
-s <directory> Specify where to place generated source files
-h <directory> Specify where to place generated native header files
-implicit:{none,class} Specify whether or not to generate class files for implicitly referenced files
-encoding <encoding> Specify character encoding used by source files
-source <release> Provide source compatibility with specified release
-target <release> Generate class files for specific VM version
-profile <profile> Check that API used is available in the specified profile
-version Version information
-help Print a synopsis of standard options
-Akey[=value] Options to pass to annotation processors
-X Print a synopsis of nonstandard options
-J<flag> Pass <flag> directly to the runtime system
-Werror Terminate compilation if warnings occur
@<filename> Read options and filenames from file
Options (36)
| Option | Description | Source |
|---|---|---|
-g | Generates all debugging information, including local variables. | help + man |
-nowarn | Disables warning messages. | help + man |
-verbose | Uses verbose output, which includes information about each class loaded and each source file compiled. | help + man |
-deprecation | Shows a description of each use or override of a deprecated member or class. | help + man |
-classpath path | Specify where to find user class files and annotation processors | help |
-cp path | Specifies where to find user class files, and (optionally) annotation processors and source files. | help + man |
-sourcepath path | Specifies the source code path to search for class or interface definitions. | help + man |
-bootclasspath path | Cross-compiles against the specified set of boot classes. | help + man |
-extdirs dirs | Overrides the location of the ext directory. | help + man |
-endorseddirs dirs | Overrides the location of the endorsed standards path. | help + man |
-processorpath path | Specifies where to find annotation processors. | help + man |
-parameters | Stores formal parameter names of constructors and methods in the generated class file so that the method java.lang.reflect.Executable.getParameters from the Reflection API can retrieve them. | help + man |
-d directory | Sets the destination directory for class files. | help + man |
-s directory | Specifies the directory where to place the generated source files. | help + man |
-h directory | Specify where to place generated native header files | help |
-encoding encoding | Sets the source file encoding name, such as EUC-JP and UTF-8. | help + man |
-source release | Provide source compatibility with specified release | help + man |
-target release | Generates class files that target a specified release of the virtual machine. | help + man |
-profile profile | When using compact profiles, this option specifies the profile name when compiling. | help + man |
-version | Prints release information. | help + man |
-help | Prints a synopsis of standard options. | help + man |
-Akey value | Options to pass to annotation processors | help |
-X | Displays information about nonstandard options and exits. | help + man |
-J flag | Pass <flag> directly to the runtime system | help |
-Werror | Terminate compilation if warnings occur | help |
-Djava.ext.dirs directories | Overrides the location of installed extensions. (in the manual page but not in --help) | man |
-Djava.endorsed.dirs directories | Overrides the location of the endorsed standards path. (in the manual page but not in --help) | man |
-Joption | Passes option to the Java Virtual Machine (JVM), where option is one of the options described on the reference page for the Java launcher. (in the manual page but not in --help) | man |
-werror | Terminates compilation when warnings occur. (in the manual page but not in --help) | man |
-Xlint | Enables all recommended warnings. (in the manual page but not in --help) | man |
-Xmaxerrs number | Sets the maximum number of errors to print. (in the manual page but not in --help) | man |
-Xmaxwarns number | Sets the maximum number of warnings to print. (in the manual page but not in --help) | man |
-Xstdout filename | Sends compiler messages to the named file. (in the manual page but not in --help) | man |
-Xprint | Prints a textual representation of specified types for debugging purposes. (in the manual page but not in --help) | man |
-XprintProcessorInfo | Prints information about which annotations a processor is asked to process. (in the manual page but not in --help) | man |
-XprintRounds | Prints information about initial and subsequent annotation processing rounds. (in the manual page but not in --help) | man |
Examples (33) from the manual page, untested
package greetings;
The source code in Hello.java:public class Hello {public static void main(String[] args) {for (int i=0; i < args.length; i++) {System.out.println("Hello " + args[i]);}}}javac greetings/Hello.java
Compile greetings.Hello:java greetings.Hello World Universe Everyone
Run greetings.Hello:Hello WorldHello UniverseHello Everyone% javac greetings/*.java
This example compiles the Aloha.java, GutenTag.java, Hello.java, and Hi.java source files in the greetings package.% ls greetingsAloha.class GutenTag.class Hello.class Hi.classAloha.java GutenTag.java Hello.java Hi.javapwd
After changing one of the source files in the previous example, recompile it:/examplesjavac greetings/Hi.javajavac -classpath /examples /examples/greetings/Hi.java
Because greetings.Hi refers to other classes in the greetings package, the compiler needs to find these other classes.javac -classpath /examples:/lib/Banners.jar \
If you change greetings.Hi to use a banner utility, then that utility also needs to be accessible through the user class path./examples/greetings/Hi.javajava -classpath /examples:/lib/Banners.jar greetings.Hi
To execute a class in the greetings package, the program needs access to the greetings package, and to the classes that the greetings classes use.javac -source 1.7 -target 1.7 -bootclasspath jdk1.7.0/lib/rt.jar \
The following example uses javac to compile code that runs on JVM 1.7.-extdirs "" OldCode.javajavac -source 1.7 OldCode.java
You must specify the -bootclasspath option to specify the correct version of the bootstrap classes (the rt.jar library).warning: [options] bootstrap class path not set in conjunction with-source 1.7javac -source 1.7 -target 1.7 -bootclasspath jdk1.7.0/lib/rt.jar \
This example uses javac to compile code that runs on JVM 1.7.-extdirs "" OldCode.javajavac -source 1.7 OldCode.java
You must specify the -bootclasspath option to specify the correct version of the bootstrap classes (the rt.jar library).warning: [options] bootstrap class path not set in conjunction with -source 1.7