Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why java complains about jar files with lots of entries?

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?

like image 734
Rogach Avatar asked Aug 26 '13 09:08

Rogach


People also ask

What is the purpose of JAR file in Java?

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.

What does a JAR file contains in Java?

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.

What is the difference between jar and ZIP files?

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 *

Do JAR files need Java?

To run a JAR file, you must install the Java JDK or JRE on your computer.


1 Answers

Why is this happening?

It's a bug in Java 1.7.0 (aka Java 7)

  • http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7191282.

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 javacs 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
like image 160
Stephen C Avatar answered Oct 03 '22 00:10

Stephen C