Java 编译打包运行

一.使用到的javac命令参数: 
--class-path <path>, -classpath <path>, -cp <path>          指定查找用户类文件和注释处理程序的位置

--source-path <path>, -sourcepath <path>           指定查找输入源文件的位置

 -d <directory>              指定放置生成的类文件的位置

二.打包编译过程

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

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值