TA的每日心情 | 开心 2021-3-12 23:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
这是我从网上看一遍文章做的练习。自解压程序是 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! 
源码下载:http://file.javaxxz.com/2014/10/1/075418312.zip |
|