1

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?

Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
  • 1
    if you have `package x;` in your java files they have to be inside folder with name `x`. – talex Nov 16 '18 at 08:30

2 Answers2

5

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
3

Proper command line will be

jar -c -m foo/manifest.mf -f foo.jar foo/*.class
talex
  • 17,973
  • 3
  • 29
  • 66