一.使用到的javac命令参数:
--class-path
--source-path
-d
二.打包编译过程
1.创建项目名:testCompile(路径 D:/testCompile)
2.创建源码路径:src (路径 D:/testCompile/src)
3.创建输出路径:target (路径 D:/testCompile/target)
4.创建Java类:TestCompile.java 、Tester.java
package com.test;
public class TestCompile {
public static void main(String args[]){
Tester.print();
}
}
package com.test;
public class Tester {
public static void print(){
System.out.println(123);
}
}
5.编译
javac -sourcepath D:\testCompile\src\ D:\testCompile\src\com\test\TestCompile.java D:\testCompile\src\com\test\Tester.java -d D:\testCompile\target\
6.编译成功,可在 D:\testCompile\target 目录下看到编辑文件夹以及文件
7.编写 MANIFEST.MF 目录(D:\testCompile\MANIFEST.MF)
Manifest-Version: 1.0
Main-Class: com.test.TestCompile
Start-Class: Main-Class: com.test.TestCompile
8.打包
jar cvfm D:\testCompile\testCompile.jar D:\testCompile\MANIFEST.MF -C D:\testCompile\target\ .
9.运行
java -jar D:\testCompile\testCompile.jar
三、拓展
1.创建拓展包lib (路径 D:/testCompile/lib)
2.创建源码包: src2 (路径 D:/testCompile/src2)
3.创建输出路径:target2 (路径 D:/testCompile/target2)
4.创建Java类:TestCompile2.java
package com.test2;
import com.test.Tester;
public class TestCompile2 {
public static void main(String args[]){
Tester.print();
}
}
5.编译
javac -sourcepath D:\testCompile\src2\ D:\testCompile\src2\com\test2\TestCompile2.java -d D:\testCompile\target2\ -cp D:\testCompile\lib\testCompile.jar
6.编写 MANIFEST2.MF 目录(D:\testCompile\MANIFEST2.MF)
Manifest-Version: 1.0
Main-Class: com.test2.TestCompile2
Start-Class: Main-Class: com.test2.TestCompile2
7.打包
jar cvfm D:\testCompile\testCompile2.jar D:\testCompile\MANIFEST2.MF -C D:\testCompile\target2\ .
8.运行
java -Djava.ext.dirs=D:\testCompile\lib\ -jar testCompile2.jar