javac 参数使用整理(未完成)

时间:2021-06-24 05:11:22

javac 参数使用整理(未完成)

@(dos)[javac|java|windows环境]



javac 文献参考


javac 具体用途

The Java Programming Language Compiler(java编译器)

  • 读取java编写的类或接口(.java),并编译成字节码文件(.class)。处理java源文件和类中的注释
    ( The javac command reads class and interface definitions, written in the Java programming language, and compiles them into bytecode class files. The javac command can also process annotations in Java source files and classes.)
  • 编译的后的字节码文件(.class)的命名与源文件(.java)一致。
  • 注:内部类编译后将独立自己的字节码文件(.class)中,且命名格式为:
    [父类类名]$[自己的类名].class

    实际例子:
    javac 参数使用整理(未完成)
    图一:如上所示为编译源文件InnerTest.java
    javac 参数使用整理(未完成)
    图二:以上代码为图一中InnerTest.java内部代码


javac 使用规格:

javac [options] [sourcefiles] [classes] [@argfiles]
参数可以是任何顺序

  • [options] 选项,即附加参数
  • [sourcefiles] 源文件,即要编译的java文件
  • [classes] 要为注释处理的一个或者多个类
  • [@argfiles] 列出选项和源文件的一个或多个文件

javac 常见参数(options) 及 简单例子

-cp 或者 -classpath 设置临时环境变量


  • 用途:指定导入类(import),依赖包(.jar)源文件等所在路径(多条路径时以分号”;”隔开)。该路径将覆盖CLASSPATH的用户环境变量。
    官方原文:Specifies where to find user class files, and (optionally) annotation processors and source files. This class path overrides the user class path in the CLASSPATH environment variable. If neither CLASSPATH, -cp nor -classpath is specified, then the user class path is the current directory. See Setting the Class Path.
  • 注:若未使用该参数,则默认为当前路径。

实际例子:
javac 参数使用整理(未完成)
d:\testA.class (只需要字节码文件即可,若无字节码文件则先编译testA.java成testA.class)
javac 参数使用整理(未完成)
d:\com\testB.java
javac 参数使用整理(未完成)
未加入-cp参数时候,用户路径为当前路径。在com文件夹中未找到testA.class
javac 参数使用整理(未完成)
加入-cp执行语句。故结果如下
javac 参数使用整理(未完成)
d:\com\

-d 目标路径