如何创建自解压的jar文件

| No Comments | No TrackBacks

这是我从网上看一遍文章做的练习。自解压程序是 ZipSelfExtractor.java(请下载),作者为 Z.S. Jin。

一、自解压jar文件的优点: 自解压jar文件可以在任意支持java的平台上解开。
二、 制作自解压jar文件的过程如下:

1、修改MANIFEST.MF文件

 随便找一个jar格式的文件,如jstl.jar,先用winzip或winRAR解压,这是因为我们要修改其中的MANIFEST.MF文件。其实修改 很简单,只要在MANIFEST.MF文件中指定(或修改)这个基于java 的解压程序包含main()方法的类的名称为:

Main-Class: ZipSelfExtractor


如将jstl.jar文件中包含的MANIFEST.MF文件:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.5.2
Created-By: 1.4.1_02-b06 (Sun Microsystems Inc.)
Specification-Title: JavaServer Pages Standard Tag Library (JSTL)
Specification-Version: 1.1
Implementation-Title: JavaServer Pages Standard Tag Library API Refere
nce Implementation
Implementation-Version: 1.1.0-D13
Implementation-Vendor: Sun Microsystems, Inc.
Implementation-Vendor-Id: com.sun
Extension-Name: javax.servlet.jsp.jstl

改为:
Manifest-Version: 1.0
Main-Class: ZipSelfExtractor
Ant-Version: Apache Ant 1.5.2
Created-By: 1.4.1_02-b06 (Sun Microsystems Inc.)
Specification-Title: JavaServer Pages Standard Tag Library (JSTL)
Specification-Version: 1.1
Implementation-Title: JavaServer Pages Standard Tag Library API Refere
nce Implementation
Implementation-Version: 1.1.0-D13
Implementation-Vendor: Sun Microsystems, Inc.
Implementation-Vendor-Id: com.sun
Extension-Name: javax.servlet.jsp.jstl

2、更新jstl.jar文件
在命令行执行如下命令:

D:\java>jar uvfm jstl.jar manifest.mf ZipSelfExtractor.class

下面是屏幕显示:
2005-9-17 11:05:10 java.util.jar.Attributes read
警告: Duplicate name in Manifest: Manifest-Version
2005-9-17 11:05:10 java.util.jar.Attributes read
警告: Duplicate name in Manifest: Main-Class
2005-9-17 11:05:10 java.util.jar.Attributes read
警告: Duplicate name in Manifest: Ant-Version
2005-9-17 11:05:10 java.util.jar.Attributes read
警告: Duplicate name in Manifest: Created-By
2005-9-17 11:05:10 java.util.jar.Attributes read
警告: Duplicate name in Manifest: Specification-Title
2005-9-17 11:05:10 java.util.jar.Attributes read
警告: Duplicate name in Manifest: Specification-Version
2005-9-17 11:05:10 java.util.jar.Attributes read
警告: Duplicate name in Manifest: Implementation-Version
2005-9-17 11:05:10 java.util.jar.Attributes read
警告: Duplicate name in Manifest: Implementation-Vendor
2005-9-17 11:05:10 java.util.jar.Attributes read
警告: Duplicate name in Manifest: Implementation-Vendor-Id
2005-9-17 11:05:10 java.util.jar.Attributes read
警告: Duplicate name in Manifest: Extension-Name
更新清单(manifest)
增加:ZipSelfExtractor.class(读入= 5290) (写出= 3031)(压缩了 42%)

D:\java>

三、测试
双击更新后的jstl.jar文件或在命令行输入:

java -jar jstl.jar

你将看到如下窗口,选择解压文件存放目录,OK!

No TrackBacks

TrackBack URL: http://www.wujianrong.com/mt-tb.cgi/1740

Leave a comment

About this Entry

This page contains a single entry by kevinwu published on February 13, 2007 2:55 PM.

WEB应用中读取配置文件 was the previous entry in this blog.

发送html格式的邮件 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.