jar包的解压和重新打包
前言
遇到一个项目,乙方需要升级依赖版本,由于之前提供乙方的已经版本已经更新了,需要在现有的版本jar包上更新依赖。
方法
解压jar包
#解压esb.jar包 jar xvf esb.jar #解压后有三个目录BOOT-INF/ META-INF/ org/ #删除现有esb.jar rm -rf esb.jar #进入依赖目录 cd BOOT-INF/lib #删除fastjson-1.2.70.jar rm -rf fastjson-1.2.70.jar #上传fastjson-1.2.83.jar rz #将所有文件重新压缩成esb.jar包 jar -cvfM0 esb.jar BOOT-INF/ META-INF/ org #将重新打包的esb.jar放回原来目录
jar 命令详情
[admin@custmer-development-d ~]$ jar help
Illegal option: h
Usage: jar {
ctxui}[vfmn0PMe] [jar-file] [manifest-file] [entry-point] [-C dir] files ...
Options:
-c create new archive
-t list table of contents for archive
-x extract named (or all) files from archive
-u update existing archive
-v generate verbose output on standard output
-f specify archive file name
-m include manifest information from specified manifest file
-n perform Pack200 normalization after creating a new archive
-e specify application entry point for stand-alone application
bundled into an executable jar file
-0 store only; use no ZIP compression
-P preserve leading / (absolute path) and ".." (parent directory) components from file names
-M do not create a manifest file for the entries
-i generate index information for the specified jar files
-C change to the specified directory and include the following file
If any file is a directory then it is processed recursively.
The manifest file name, the archive file name and the entry point name are
specified in the same order as the m, f and e flags.
Example 1: to archive two class files into an archive called classes.jar:
jar cvf classes.jar Foo.class Bar.class
Example 2: use an existing manifest file mymanifest and archive all the
files in the foo/ directory into classes.jar:
jar cvfm classes.jar mymanifest -C foo/ .
用法:jar {
ctxui} [vfmn0PMe] [jar文件] [清单文件] [入口点] [-C目录]文件...
选项:
-c创建新档案
-t列出要归档的目录
-x从存档中提取命名(或所有)文件
-u更新现有档案
-v在标准输出上生成详细输出
-f指定归档文件名
-m包含来自指定清单文件的清单信息
-n在创建新存档后执行Pack200规范化
-e指定独立应用程序的应用程序入口点
捆绑到可执行的jar文件中
-0只存储;不使用ZIP压缩
-P从文件名保留前导的“ /”(绝对路径)和“ ..”(父目录)组件
-M不为条目创建清单文件
-i为指定的jar文件生成索引信息
-C更改为指定目录并包含以下文件
如果任何文件是目录,则将对其进行递归处理。
清单文件名称,归档文件名称和入口点名称为
以与“ m”,“ f”和“ e”标志相同的顺序指定。
示例1:将两个类文件归档到名为classes.jar的归档文件中:
jar cvf classes.jar Foo.class Bar.class
示例2:使用现有清单文件“ mymanifest”并将所有
foo /目录中的文件放入“ classes.jar”:
jar cvfm classes.jar mymanifest -C foo /
特殊情况
可能会遇到使用jar解压失效的情况,这种情况可能是JDK版本问题,打包时的JDK和解压时的JDK版本不一样,需要保证打包和解压的JDK版本一直性,目前遇到过这种情况。实在不能解压的可以尝试使用360解压,然后再用360压缩(同事尝试时是可以的)。
下一篇:
基于Python的简易评论区抽奖
