Jar manifest error – java.io.IOException: invalid header field

Often times, this error is causing by the mismatch order between “m” and “f” Jar options.

For example,

 
jar -cvfm manifest.txt example.jar com/mkyong/awt/*.class

The above command will causing the following error :


java.io.IOException: invalid header field
	at java.util.jar.Attributes.read(Attributes.java:406)
	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:150)
	at sun.tools.jar.Main.main(Main.java:1044)

Did you spot the error? The “m” and “manifest” is not match, the system is consider your manifest file as “example.jar” :)

The letters “m” and “f” must appear in the same order that “manifest” and “jarfile” appear.

The working command should be

 
jar -cvmf manifest.txt example.jar com/mkyong/awt/*.class

Please read this article about the correct way to add manifest into your Jar file.

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

Leave a Reply

avatar
newest oldest most voted
AVS
Guest
AVS

saved my day. Thanks

Ahmed
Guest
Ahmed

Hallo Sir,

I still have the same problem.

a:HelloWorld ahmed$ jar -cvfm HelloWorld.jar Manifest.txt HelloWorld.class
java.io.IOException: invalid header field
at java.util.jar.Attributes.read(Attributes.java:406)
at java.util.jar.Manifest.read(Manifest.java:199)
at java.util.jar.Manifest.(Manifest.java:69)
at sun.tools.jar.Main.run(Main.java:172)
at sun.tools.jar.Main.main(Main.java:1177)

Ahmed
Guest
Ahmed

I fixed it! :)

I was using the Mac program “TextEdit” and that’s why i had the error..

TextWrangler fixed the problem! :D

sites
Guest
sites

I simply wanted to appreciate you once more. I’m not certain what I might have made to happen in the absence of the actual creative ideas provided by you about such a concern. It previously was a horrifying problem in my position, however , observing a new professional technique you resolved the issue took me to weep over contentment. Extremely happier for this information and in addition pray you are aware of a great job you are providing instructing most people by way of a web site. Most probably you haven’t come across all of us.

TereBentikh
Guest
TereBentikh

YOU ARE MARVELOUS, I HAVE BEEN 2 DAYS SEARCHING FOR THIS ANSWER

Maddy
Guest
Maddy

Thanks… you saved me sometime! :)