正文

如何创建自解压的jar文件2006-04-22 18:11:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/sword2008/13036.html

分享到:

这是我从网上看一遍文章做的练习。自解压程序是 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!


阅读(6335) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册