Search code examples
javajarexecutable-jarrunnable-jar

Cannot build with jar command - java.io.IOException: line too long


I have folder that looks like so:

foo/
 Bar.java
 Bar.class
 Foo.java
 Foo.class
 manifest.mf

the .java files are both in a package called x:

package x;

I generate the .class files with:

javac foo/*.java

then I try to package to runnable jar format with:

jar cmf foo.jar foo/manifest.mf foo/*.class

but I get this error:

 java.io.IOException: line too long
        at java.base/java.util.jar.Attributes.read(Attributes.java:381)
        at java.base/java.util.jar.Manifest.read(Manifest.java:228)
        at java.base/java.util.jar.Manifest.<init>(Manifest.java:80)
        at java.base/java.util.jar.Manifest.<init>(Manifest.java:72)
        at jdk.jartool/sun.tools.jar.Main.run(Main.java:264)
        at jdk.jartool/sun.tools.jar.Main.main(Main.java:1669)

The manifest.mf contents are just:

Main-Class: x.Bar

It compiles with javac so not sure what's going on, or why it doesn't like the manifest file, anyone know?


Solution

  • Proper command line will be

    jar -c -m foo/manifest.mf -f foo.jar foo/*.class