Java Tools Tutorials - Herong's Tutorial Examples - v6.23, by Herong Yang
javac - Java Compilation Command and Options
This section describes what are the commonly used command line options for the Java compiler - 'javac' tool.
What Is "javac"? - "javac" is a command line tool that reads Java source files and compiles them into bytecode class files.
"javac" has been included in JDK installation since JDK 1.0. And it is represented by the %java_home%\bin\javac.exe program file.
"javac" has the following syntax:
javac [options] [sourcefiles]
where "options" is a list of options and "sourcefiles" is a list of Java source files.
Commonly used "javac" options are:
You can run "javac" by typing in "jmc" at the command prompt, if you have %java_home%\bin directory included in "path" the environment variable. If the "javac" command is executed without any options, it will display the quick usage information as shown below:
herong> javac 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 -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} 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: 7, 8, 9, 10, 11, 12 -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
For more information, see "javac" reference page at https://docs.oracle.com/en/java/javase/17/docs/specs/man/javac.html.
Table of Contents
►javac - The Java Program Compiler
►javac - Java Compilation Command and Options
Compiling Hello.java - My First Java Program
"javac -classpath" - Specifying Class Path
"javac -verbose" - Printing Compilation Details
"javac -sourcepath" - Specifying Source Path
"javac -d" - Specifying Output Directory
Two Types of "import" Statements
"import" Statements Processed by "javac"
"javac -g" - Controlling Debugging Information
"javac --module" - Compiling Entire Module
"javac -X" - Specifying Non-Standard Options
java - The Java Program Launcher
jpackage - Binary Package Builder
javadoc - The Java Document Generator
jdeps - The Java Class Dependency Analyzer
jdeprscan - The Java Deprecated API Scanner
jcmd - The JVM Diagnostic Tool
jconsole - Java Monitoring and Management Console
jstat - JVM Statistics Monitoring Tool
jhsdb - The Java HotSpot Debugger
jvisualvm (Java VisualVM) - JVM Visual Tool
javap - The Java Class File Disassembler
keytool - Public Key Certificate Tool
jrunscript - Script Code Shell
native2ascii - Native-to-ASCII Encoding Converter