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
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?
A JAR (Java Archive) is a package file format typically used to aggregate many Java class files and associated metadata and resources (text, images, etc.) into one file to distribute application software or libraries on the Java platform.
A Java Archive, or JAR file, contains all of the various components that make up a self-contained, executable Java application, deployable Java applet or, most commonly, a Java library to which any Java Runtime Environment can link. There are two key benefits of using a JAR file.
jar files contain mainly Java code but zip files contain anything. jar files can contain META-INF/MANIFEST. MF in a specific format, but zip files normally don't * jar files can be added to an application's classpath, but zip files normally cannot *
To run a JAR file, you must install the Java JDK or JRE on your computer.
Why is this happening?
It's a bug in Java 1.7.0 (aka Java 7)
Fixed in Java 1.7.0 p40 or later, apparently.
Is there a way to fix it?
According to the bug report, the workaround (for Java 1.7.0) is to launch the application without using the -jar
option.
FWIW, there is also a bug in javac
s handling of ZIP64 format JAR files:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With