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

843 views Asked by At

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?

2

There are 2 answers

2
talex On BEST ANSWER

Proper command line will be

jar -c -m foo/manifest.mf -f foo.jar foo/*.class
0
Yevhen Zhovtonoh On

I believe that for "jar cmf" command first argument should be path to manifest. As described in documentation https://docs.oracle.com/javase/7/docs/technotes/tools/windows/jar.html

Could you try in your case build it with next command ?

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