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

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

问题描述

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

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

问题在于我想要更新JAR中的JAR(或任何文件),但是文件位于文件夹结构中,我希望避免在JAR之外复制,以便我可以更新它。

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.

示例:

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

所以,如果我想要的话要使用 jar 命令更新它,我必须首先在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

但是我想避免创建这个文件夹结构,因为对于某些文件它可能非常深,而且因为我可能需要更新整个容器JAR中的选定文件,所以我不想创建具有特定结构的这么多文件夹只是这样 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.

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

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.

即类似

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).

可以这样做吗?当我发现 jar 命令可以找到匹配的东西时,我绝对需要模仿整个文件夹结构,因为我可能需要更新一个文件。文件夹结构,深度为100个文件夹。重新生成文件会非常复杂。

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.

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

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.

我忘了说我也想避免不得不解开,更新,重新调整整个事情,因为这个JAR可以上升到2GB所以需要一个虽然这样做只是为了,基本上,添加一个小资源文件到我巨大的JAR。

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.

非常感谢任何帮助!

推荐答案

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

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.

来自评估:

很容易同情那些希望修复此错误的人。或许更容易同情那些无意中覆盖正在运行的JVM正在使用的JAR文件的人。

"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."

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

"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天全站免登陆