为什么java会抱怨有大量条目的jar文件? [英] Why java complains about jar files with lots of entries?
问题描述
我偶然发现了以下问题 - 当我创建超过65k条目的 .jar
文件时,java会抱怨无效或损坏jarfile。示例:
I stumbled upon following problem - when I create .jar
file with more than 65k entries, java complains "Invalid or corrupt jarfile". Example:
$ # in fresh dir
$ for i in {1..70000}; do touch $i; done
$ jar cf app.jar {1..70000}
$ java -jar app.jar
Error: Invalid or corrupt jarfile app.jar
但是如果我使用的文件少一些,那就可以了:
But if I use a bit less files, it works:
$ jar cf app.jar {1..60000}
$ java -jar app.jar
no main manifest attribute, in app.jar
我听说旧的 .zip
文件格式有65k个文件限制,但是Java 7默认情况下应该使用ZIP64。为什么会这样?有没有办法解决它?
I heard that there was 65k files limit in old .zip
file format, but Java 7 should use ZIP64 by default already. Why is this happening? Is there a way to fix it?
推荐答案
为什么会发生这种情况?
Why is this happening?
这是Java 1.7.0(又名Java 7)中的一个错误
It's a bug in Java 1.7.0 (aka Java 7)
- http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7191282.
显然在Java 1.7.0 p40或更高版本中已修复。
Fixed in Java 1.7.0 p40 or later, apparently.
有没有办法解决它?
Is there a way to fix it?
根据错误报告,解决方法(适用于Java 1.7) .0)是在不使用 -jar
选项的情况下启动应用程序。
According to the bug report, the workaround (for Java 1.7.0) is to launch the application without using the -jar
option.
FWIW, javac
处理ZIP64格式的JAR文件时还有一个错误:
FWIW, there is also a bug in javac
s handling of ZIP64 format JAR files:
- http://openjdk.5641.n7.nabble.com/javac-doesn-t-work-with-jar-files-with-64k-entries-tp103719p103816.html
- http://openjdk.5641.n7.nabble.com/8003512-javac-doesn-t-work-with-jar-files-with-64k-entries-tp109359.html
- http://openjdk.5641.n7.nabble.com/javac-doesn-t-work-with-jar-files-with-64k-entries-tp103719p103816.html
- http://openjdk.5641.n7.nabble.com/8003512-javac-doesn-t-work-with-jar-files-with-64k-entries-tp109359.html
这篇关于为什么java会抱怨有大量条目的jar文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!