C:\Program Files (x86)\Java\jdk1.8.0_102\bin>jar -h
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/ .


C:\Program Files (x86)\Java\jdk1.8.0_102\bin>

C:\Users\chenjo>jar -h
非法选项: h
用法: jar {ctxui}[vfmn0PMe] [jar-file] [manifest-file] [entry-point] [-C dir] files ...
选项:
    -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 tvf cos-26Dec2008.jar | grep Daemon.class
  1790 Tue Nov 12 23:46:32 CST 2013 com/oreilly/servlet/Daemon.class

$ jar tvf cos-26Dec2008.jar | grep Daemon.class | awk '{print $8}'
com/oreilly/servlet/Daemon.class

$ jar tvf cos-26Dec2008.jar | grep Daemon.class | awk '{print $8}'| xargs dirname
com/oreilly/servlet

$ jar tvf cos-26Dec2008.jar | grep Daemon.class | awk '{print $8}'| xargs dirname | xargs mkdir -p

部署在 Google云里的应用突然有一个类做了修改,删除掉重新上传的话,一个jar包传上去就得等半小时,墙有点高,你懂的,所以要是能单独更新某个class文件就最棒了,方法当然是有的,如下所示。

jar tvf test.jar  | less
// OR: unzip -v test.jar | grep xxx

通过上面命令搜索出自己要更新的class文件的目录,在当前路径下建立好目录

mkdir -p  BOOT-INF/classes/net/yuxianghe/core/
cp Test.class BOOT-INF/classes/net/yuxianghe/core/

要更新的class的目录建立好了之后直接更新到jar里即可,如下命令所示:

jar -uvf test.jar  BOOT-INF/classes/net/yuxianghe/core/Test.class

到这里就做到了只更新jar包里的单个类文件

08-17 16:12