关于jar打包

1 使用JAR命令
1)创建JAR文件
The basic format of the command for creating a JAR file is:
    jar cf jar-file input-file(s)
options and arguments:
    c: indicates to create a JAR file.
    f: indicates output to a file,如果是文件夹,则会将整个文件下的内容(包括子目录)打包,文件名中可使用通配符*
other Options and arguments
    v: produces output and std output
    0: indicates not to compress the jar file
    M: indicates that the default manifest file should not be produced
    m: using existing manifest file
        jar cmf existing-manifest jar-file input-file(s)
    -C: To change directories during execution of the command

2) To view the content of a JAR file           jar tf jar-file
    t: indicates to view the table of contents of jar file
3) To extract the contents of a JAR file       jar xf jar-file
    x: indicates to extract jar file or specific files
4) To extract specific files from a JAR file   jar xf jar-file archived-file(s)
5) To run an application packaged as a JAR file(requires Main-Class manifest header)
  java -jar app.jar


关于MANIFEST.MF文件
创建JAR文件的时候,将会自动生成一个默认的manifest文件,一个jar包中只能有一个manifest文件,并只能在META-INF/MANIFEST.MF路径中
默认的manifest文件包括以下的内用
Manifest-Version: 1.0       //版本号
Created-By: 1.4.2_07 (Sun Microsystems Inc.)

一些特殊用途的MANIFEST头
JAR应用程序:
Main-Class: 定义jar中应用程序的入口class, 用java -jar app.jar时将会直接调用该class中的public static void main(String[] args)方法,如下:
Main-Class: com.cmm.test.ServerTest

使用第三方jar文件,如下
Class-Path: servlet.jar infobus.jar ./lib/beans.jar 运行该jar包时,将会搜索该jar文件相同目录下的servlet.jar, infobus.jar以及子目录lib下的beans.jar文件。

版本信息 如下格式
Name: java/util/
Specification-Title: "Java Utility Classes"
Specification-Version: "1.2"
Specification-Vendor: "Sun Microsystems, Inc.".
Implementation-Title: "java.util"
Implementation-Version: "build57"
Implementation-Vendor: "Sun Microsystems, Inc."

一个包含入口class和第三方jar package的MANIFEST.MF文件如下
Manifest-Version: 1.0
Created-By: 1.4.2_07 (Sun Microsystems Inc.)
Main-Class: com.cmm.test.ServerTest
Class-Path: ./log4j_128.jar ./lib/log4j_128.jar

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值