javac.exe(java compiler),即java语言编程编译器,javac 工具读取用 Java 编程语言编写的类和接口定义,并将它们编译成字节码类文件。
用法: javac < options > < source files >
其中,有两个参数是很常用的,即 -cp 和 -d
--class-path < path >, -classpath < path >, -cp < path >
指定查找用户类文件和注释处理程序的位置
-d <directory> 指定放置生成的类文件的位置
javac文档 https://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html
-cp path or -classpath path
Specify 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, the user class path consists of the current directory. See Setting the Class Path for more details.
If the -sourcepath option is not specified, the user class path is also searched for source files.
If the -processorpath option is not specified, the class path is also searched for annotation processors.
java.exe,解释器,启动jvm,解释字节码文件,运行程序。
用法:java [options] <主类> [args…](执行类)
或 java [options] -jar <jar 文件> [args…](执行 jar 文件)
或 java [options] -m <模块>[/<主类>] [args…]
java [options] --module <模块>[/<主类>] [args…](执行模块中的主类)
或 java [options] <源文件> [args](执行单个源文件程序)
java文档 https://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html
同样有几个很常用的参数
-cp <目录和 zip/jar 文件的类搜索路径>
-classpath <目录和 zip/jar 文件的类搜索路径>
--class-path <目录和 zip/jar 文件的类搜索路径>
使用 ; 分隔的, 用于搜索类文件的目录, JAR 档案
和 ZIP 档案列表。
注意:
-cp 参数是用来寻找所需要导入的 class文件的或所需资源的,所以在 javac命令中不能拿来寻找需要被编译的java源文件,而是应该使用 javac <java源文件路径 > 来编译,例如
javac E:\demo\demo.java
而在 java命令中,-cp除了指向所需导入的class文件和资源外,也可以指向所需执行的class文件,例如
java -cp E:\demo\classes p1.demo
另外class文件应写出全名,也就是带上包名