7

When i try to run the following command :

jar cvfm myjar.jar manifest.txt *.class

I get the following exceptions :

java.io.IOException: invalid header field
    at java.util.jar.Attributes.read(Attributes.java:410)
    at java.util.jar.Manifest.read(Manifest.java:199)
    at java.util.jar.Manifest.<init>(Manifest.java:69)
    at sun.tools.jar.Main.run(Main.java:171)
    at sun.tools.jar.Main.main(Main.java:1176)

What could be the reason i am getting these exceptions ?

Suhail Gupta
  • 22,386
  • 64
  • 200
  • 328

5 Answers5

6

I'm guessing that there's a problem with your manifest file. Give it a look to see if you've got a typo in the name of a header variable.

duffymo
  • 305,152
  • 44
  • 369
  • 561
1

Check that your manifest.txt file contains the content in this manner :

Main-Class: <"package-name">.<"Main-class-name">.class <"newline">

Note that newline/carriage-return is necessary for parsing.

Refer to this link http://docs.oracle.com/javase/tutorial/deployment/jar/appman.html

dograditya
  • 26
  • 4
0

"jar -cvmf" instead of "jar cvfm" should resolve the above error

0

I solved a similar problem. It's always the first manifest header makes JAR throw an "invalid header" IOException. So I guess it's the BOM of a utf-8 file makes Jar can't understand. Although I think I have read somewhere that saying a manifest file should utf-8 encoded, I saved my mf file to ANSI with Notepad of Windows, and JAR just stopped complaining about the header name.

0

A stupid mistake to do (which I did) was to do jar cvfm manifest.txt myjar.jar *.class instead of jar cvfm myjar.jar manifest.txt *.class

Thomas
  • 8,306
  • 8
  • 53
  • 92