使用 jar 命令更新特定目录中 JAR 中的文件 [英] Update a file inside a JAR in a specific directory with jar command

查看:27
本文介绍了使用 jar 命令更新特定目录中 JAR 中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我一直在寻找答案,显然没有找到满意的答案.

问题是我想更新 JAR 内的 JAR(或任何与此相关的文件),但所述文件位于文件夹结构内,我想避免在 JAR 外复制,以便我可以更新它.

示例:

Foo.jar(根目录)/|->/folder1||->/folder2||->/foo||-->/bar||---->/baz||------>file_to_update.jar

因此,如果我想使用 jar 命令更新它,我必须首先在 JAR 之外创建相同的文件夹结构,然后再执行

jar -uf Foo.jar -C foo/bar/baz/file_to_update.jar

但是,我想避免创建此文件夹结构,因为对于某些文件,它可能非常深,还因为我可能需要更新整个容器 JAR 中的选定文件,所以我不想创建这么多带有特定的结构,以便 jar 命令可以更新它们.

换句话说,我想告诉 jar 命令使用特定源目录中的特定源文件更新特定目标目录中的特定目标文件.>

即像

jar -uf Foo.jar -sourceFile/x/y/z/filetoupdate -destFile/a/b/c/filetoupdate

(我知道这个语法行不通,只是为了举例说明我需要什么).

这能做到吗?当 jar 命令可以找到匹配项或其他内容时,我绝对需要模仿整个文件夹结构,这让我感到非常奇怪,因为我可能需要更新100 个文件夹深的文件夹结构.仅仅为了更新文件而复制它会过于复杂.

另外,我知道可以使用常规的 ZIP 实用程序,但是我在 Linux 中可用的那个实用程序没有更新文件,即使它说更新了(重新打开 jar 后,旧版本完好无损),现在我不能去寻找另一个(公司政策,没有时间,测试问题,等等).

最后,如果我可以从命令行执行此操作,则意味着我可以创建一个批处理文件来更新大量特定文件,而无需创建文件夹结构.

我忘了说我还想避免解压、更新、重新打包整个过程,因为这个 JAR 可以上升到 2GB,所以这样做需要一段时间,基本上只是为了添加一点资源文件到我的巨大 JAR.

非常感谢您对此的任何帮助!

解决方案

4129445 :用于增量更新 Sun/Oracle 错误数据库中的 ZIP 文件的 API 要求在 java api 中实现此功能.

来自评估:

很容易同情那些想要修复此错误的人.同情那些无意中覆盖了正在运行的 JVM 已在使用的 JAR 文件的人可能更容易同情."

如果 jar & zip API 从第一天起就允许可变的 zip 文件,那就太好了.但是在这一点上,为来自 Java 的 jar 和 zip 文件添加可变性(或者更确切地说,增加了改变它们的容易程度)) 似乎可能会引入更多难以调试的问题."

So I've been looking high and low for an answer to this and obviously haven't found a satisfactory answer.

The problem is that I want to update a JAR (or any file for that matter) inside a JAR, but said file is inside a folder structure, which I would like to avoid reproducing outside the JAR just so I can update it.

Example:

Foo.jar (root directory)
/
|->/folder1
|
|->/folder2
|
|->/foo
    |
    |-->/bar
         |
         |---->/baz
               |
               |------>file_to_update.jar

So, if I want to update this using the jar command, I would have to first create the same folder structure outside the JAR and then do

jar -uf Foo.jar -C foo/bar/baz/file_to_update.jar

However I would like to avoid creating this folder structure since for certain files it can be quite deep and also because I might need to update selected files all over the container JAR, so I would not like to create so many folders with a specific structure just so the jar command can update them.

To put it in another way, I would like to tell the jar command to update a specific destination file inside a specific destination directory, using a specific source file inside a specific source directory.

I.e. something like

jar -uf Foo.jar -sourceFile /x/y/z/filetoupdate -destFile /a/b/c/filetoupdate 

(I know this syntax doesn't work, it's just to exemplify what I need).

Can this be done? It would strike me as very odd that I would absolutely need to mimic the whole folder structure when the jar command could find a match for it or something, since I could have the need to update a file inside a folder structure that is 100 folders deep. That would be overly complex to reproduce just to update the file.

Also, I know a regular ZIP utility could be used, but the one I have available in Linux is not updating the file even if it says it did (upon re-opening the jar, it has the old version intact), and right now I can't go looking for another one (company policy, no time, testing issues, you name it).

Finally, if I can do this from a command line, it means I can create a batch file to update lots of specific files without having to create the folder structure.

I forgot to say that I would also like to avoid having to unjar, update, rejar the whole thing, as this JAR can go upwards to 2GB so it takes a while to do this just to, basically, add a little resource file to my gigantic JAR.

Any help on this is greatly appreciated!

解决方案

4129445 : An API to incrementally update ZIP files in the Sun/Oracle bug database asks for this feature to be implemented in the java api.

From the Evaluation:

"It is easy to sympathize with those who want this bug fixed. It is perhaps easier to sympathize with those who have, inadvertently, overwritten JAR files that are already in-use by a running JVM."

and

"It would have been nice if the jar & zip APIs had allowed for mutable zip files from day one. But at this point adding mutability to jar & zip files from Java(or rather, increasing the ease of mutating them) seems likely to introduce more hard-to-debug problems."

这篇关于使用 jar 命令更新特定目录中 JAR 中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆