Reads Java class and interface definitions and compiles them into bytecode and class files.
javac是用来编译 .java 文件的。
Usage: javac
where possible options include:
@ Read options and filenames from file
-Akey[=value] Options to pass to annotation processors
--add-modules (,)*
Root modules to resolve in addition to the initial modules, or all modules on the module path if is ALL-MODULE-PATH.
--boot-class-path , -bootclasspath
Override location of bootstrap class files
--class-path , -classpath , -cp
Specify where to find user class files and annotation processors
-d 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 Specify character encoding used by source files
-endorseddirs Override location of endorsed standards path
-extdirs 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 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 Pass directly to the runtime system
--limit-modules (,)*
Limit the universe of observable modules
--module , -m
Compile only the specified module, check timestamps
--module-path , -p Specify where to find application modules
--module-source-path
Specify where to find input source files for multiple modules
--module-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 [,,...]
Names of the annotation processors to run; bypasses default discovery process
--processor-module-path Specify a module path where to find annotation processors
--processor-path , -processorpath
Specify where to find annotation processors
-profile Check that API used is available in the specified profile
--release Compile for a specific VM version. Supported targets: 6, 7, 8, 9, 10, 11
-s Specify where to place generated source files
-source
Provide source compatibility with specified release
--source-path , -sourcepath
Specify where to find input source files
--system |none Override location of system modules
-target Generate class files for specific VM version
--upgrade-module-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
这里介绍一个最基本的用法,以 helloworld 为例,按照 IntelliJ IDEA 的文件组织结构编译java文件为class文件:
cd "C:\Data\Code\GitHub\GeekbangJavaTrainingCamp\Week_01\Bytecode\bytecode"
javac "src\main\java\org\example\helloworld\HelloByteCode.java" -d "target\classes"
javap
javap (Java Disassembler): Disassembles one or more class files.
javap是JDK提供的一个命令行工具,javap能对给定的class文件提供的字节代码进行反编译。
通过它,可以对照源代码和字节码,从而了解很多编译器内部的工作,对更深入地理解如何提高程序执行的效率等问题有极大的帮助。
Usage: javap <options> <classes>
where possible options include:
-? -h --help -help Print this help message
-version Version information
-v -verbose Print additional information
-l Print line number and local variable tables
-public Show only public classes and members
-protected Show protected/public classes and members
-package Show package/protected/public classes and members (default)
-p -private Show all classes and members
-c Disassemble the code
-s Print internal type signatures
-sysinfo Show system info (path, size, date, MD5 hash) of class being processed
-constants Show final constants
--module <module>, -m <module> Specify module containing classes to be disassembled
--module-path <path> Specify where to find application modules
--system <jdk> Specify where to find system modules
--class-path <path> Specify where to find user class files
-classpath <path> Specify where to find user class files
-cp <path> Specify where to find user class files
-bootclasspath <path> Override location of bootstrap class files
GNU-style options may use = instead of whitespace to separate the name of an option
from its value.
Each class to be shown may be specified by a filename, a URL, or by its fully
qualified class name. Examples:
path/to/MyClass.class
jar:file:///path/to/MyJar.jar!/mypkg/MyClass.class
java.lang.Object