Usage: javac <options> <source files>
where possible options include:
@<filename> Read options and filenames from file
-Akey[=value] Options to pass to annotation processors
--add-modules <module>(,<module>)*
Root modules to resolve in addition to the initial modules, or all modules
on the module path if <module> is ALL-MODULE-PATH.
--boot-class-path <path>, -bootclasspath <path>
Override location of bootstrap class files
--class-path <path>, -classpath <path>, -cp <path>
Specify where to find user class files and annotation processors
-d <directory> Specify where to place generated class files
-deprecation
Output source locations where deprecated APIs are used
--enable-preview
Enable preview language features. To be used in conjunction with either -source or --release.
-encoding <encoding> Specify character encoding used by source files
-endorseddirs <dirs> Override location of endorsed standards path
-extdirs <dirs> Override location of installed extensions
-g Generate all debugging info
-g:{lines,vars,source} Generate only some debugging info
-g:none Generate no debugging info
-h <directory>
Specify where to place generated native header files
--help, -help, -? Print this help message
--help-extra, -X Print help on extra options
-implicit:{none,class}
Specify whether or not to generate class files for implicitly referenced files
-J<flag> Pass <flag> directly to the runtime system
--limit-modules <module>(,<module>)*
Limit the universe of observable modules
--module <module-name>, -m <module-name>
Compile only the specified module, check timestamps
--module-path <path>, -p <path>
Specify where to find application modules
--module-source-path <module-source-path>
Specify where to find input source files for multiple modules
--module-version <version>
Specify version of modules that are being compiled
-nowarn Generate no warnings
-parameters
Generate metadata for reflection on method parameters
-proc:{none,only,full}
Control whether annotation processing and/or compilation is done.
-processor <class1>[,<class2>,<class3>...]
Names of the annotation processors to run; bypasses default discovery process
--processor-module-path <path>
Specify a module path where to find annotation processors
--processor-path <path>, -processorpath <path>
Specify where to find annotation processors
-profile <profile>
Check that API used is available in the specified profile
--release <release>
Compile for a specific VM version. Supported targets: 6, 7, 8, 9, 10, 11
-s <directory> Specify where to place generated source files
-source <release>
Provide source compatibility with specified release
--source-path <path>, -sourcepath <path>
Specify where to find input source files
--system <jdk>|none Override location of system modules
-target <release> Generate class files for specific VM version
--upgrade-module-path <path>
Override location of upgradeable modules
-verbose Output messages about what the compiler is doing
--version, -version Version information
-Werror Terminate compilation if warnings occur
Options (45)
| Option | Description | Source |
|---|---|---|
-Akey value | Options to pass to annotation processors | help |
--add-modules module>( | Root modules to resolve in addition to the initial modules, or all modules on the module path if <module> is ALL-MODULE-PATH. | help |
-d directory | Sets the destination directory for class files. | help + man |
-deprecation | Shows a description of each use or override of a deprecated member or class. | help + man |
--enable-preview | Enable preview language features. | help |
-encoding encoding | Sets the source file encoding name, such as EUC-JP and UTF-8. | help + man |
-endorseddirs dirs | Overrides the location of the endorsed standards path. | help + man |
-extdirs dirs | Overrides the location of the ext directory. | help + man |
-g | Generates all debugging information, including local variables. | help + man |
-h directory | Specify where to place generated native header files | help |
--help, -help, -? | Prints a synopsis of standard options. | help + man |
--help-extra, -X | Displays information about nonstandard options and exits. | help + man |
-J flag | Pass <flag> directly to the runtime system | help |
--limit-modules module>( | Limit the universe of observable modules | help |
--module-source-path module-source-path | Specify where to find input source files for multiple modules | help |
--module-version version | Specify version of modules that are being compiled | help |
-nowarn | Disables warning messages. | 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 |
-processor class1 | Names of the annotation processors to run; | help |
--processor-module-path path | Specify a module path where to find annotation processors | help |
-profile profile | When using compact profiles, this option specifies the profile name when compiling. | help + man |
--release release | Compile for a specific VM version. | help |
-s directory | Specifies the directory where to place the generated source files. | help + man |
-source release | Provide source compatibility with specified release | help + man |
--system jdk>|none | Override location of system modules | help |
-target release | Generates class files that target a specified release of the virtual machine. | help + man |
--upgrade-module-path path | Override location of upgradeable modules | help |
-verbose | Uses verbose output, which includes information about each class loaded and each source file compiled. | help + man |
--version, -version | Prints release information. | help + man |
-Werror | Terminate compilation if warnings occur | help |
-cp, -classpath path | Specifies where to find user class files, and (optionally) annotation processors and source files. (in the manual page but not in --help) | man |
-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 |
-processorpath path | Specifies where to find annotation processors. (in the manual page but not in --help) | man |
-sourcepath sourcepath | Specifies the source code path to search for class or interface definitions. (in the manual page but not in --help) | man |
-werror | Terminates compilation when warnings occur. (in the manual page but not in --help) | man |
-bootclasspath bootclasspath | Cross-compiles against the specified set of boot classes. (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