更新jar中的文件会抛出ZipException [英] Updating file in a jar throws ZipException

查看:173
本文介绍了更新jar中的文件会抛出ZipException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下命令更新现有jar中的文件(在此示例中为antlr):

I'm trying to update a file in an existing jar (in this example antlr) using the command:

jar -uf antlrworks-1.2.3.jar org/antlr/codegen/templates/Java/Java.stg 

但我得到以下消息


java.util.zip.ZipException:重复条目:antlr / ANTLRError.class
at java.util.zip.ZipOutputStream.putNextEntry(ZipOutputStream.java:175)
at java.util.jar.JarOutputStream.putNextEntry(JarOutputStream.java:92)
at sun.tools.jar.Main。更新(Main.java:508)
at sun.tools.jar.Main.run(Main.java:185)
at sun.tools.jar.Main.main(Main.java:1044)

java.util.zip.ZipException: duplicate entry: antlr/ANTLRError.class at java.util.zip.ZipOutputStream.putNextEntry(ZipOutputStream.java:175) at java.util.jar.JarOutputStream.putNextEntry(JarOutputStream.java:92) at sun.tools.jar.Main.update(Main.java:508) at sun.tools.jar.Main.run(Main.java:185) at sun.tools.jar.Main.main(Main.java:1044)

任何想法?

推荐答案

你正在尝试做正确的事情,但jar文件有问题 - 它有两次相同的条目:((这对于zip文件来说是合法的,但不是真的有用 - 而且你可以看到,它是m akes jar 投诉。)

You're trying to do the right thing, but the jar file is problematic - it's got the same entry twice :( (This is legal for a zip file, but not really helpful - and as you can see, it makes jar complain.)

如果你运行

jar tvf antlrworks-1.2.3.jar > contents

然后查看生成的内容文件你会看到有各种重复的文件。您应该将此报告给antlr项目(在检查后他们还不知道)。

and then look at the generated contents file you'll see that there are various duplicate files. You should probably report this to the antlr project (after checking they don't already know).

作为一种解决方法,您可以提取jar文件的内容,jar再次,然后你将有一个可以更新的工作jar文件。 (如果你只需要这样做一次,你可以提取,把你想要的文件放在那里,然后将整个罐子装罐,而不是事后更新。)

As a workaround, you can extract the contents of the jar file, jar it up again, and then you'll have a "working" jar file you can update. (If you only need to do this once, you can just extract, put the file you want in there, and then jar the whole lot up rather than updating it afterwards.)

这篇关于更新jar中的文件会抛出ZipException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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