java课程设计 博客园_Java jar

In CMD, we can use the JDK's command: jar. (You have to first of all configure correctly the CMD environment variables)

1. To pack two .class files into an archive named testPackage.jar

jar cvf testPackage.jar classFile1.class classFile2.class

2. To pack two .class files into an archive named testPackage2.jar with the usage of a existant manifest file "manifestForTest.MF"

jar cvfm testPackage2.jar manifestForTest.MF classFile1.class classFile2.class

3. To pack all the .class files in a folder specified into an archive named testPackage3.jar with the usage of a existant manifest file "manifestForTest.MF"

jar cvfm testPackage3.jar manifestForTest.MF -C folderPath

示例:

1342771171_9183.png

1. 清单文件manifest,对格式要求很高,注意每个冒号后面要有一个空格,文件最后要有一个空行。

2. 对于引用到外部jar包的工程,需要在manifeste中定义好Class-Path属性。

In Eclipse, you can use the related GUI guide for creating .jar file. But I encountered a problem : the eclipse GUI guide can not see the images files in the same level folder as the class files. (The images can thus be easily accessed by this.getClass().getResource()

in the java codes.) So in that case we have no choice but to use the commands.

For executing .jar files, you have only to use the command: java -jar jarFile ...

If you want to see the informations output by System.out.println(), you can type: java -jar jarFile > log.txt

You can also use a .bat file to process, in the .bat file: java -jar jarFile > log.txt

总之,你首先要思考的就是:Jar是在别人机器也可以运行的,所以就知道需要打包除标准JRE中自带的API(更广泛的说是在JDK中的src.zip)之外所有资源。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值