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.
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.(Manifest.java:69)
at sun.tools.jar.Main.run(Main.java:172)
at sun.tools.jar.Main.main(Main.java:1177)
i don’t get this error with edit plus but i get this when the same work done with notepad
what is the reason?
saved my day. Thanks
Hi M K Yong
This will happens if there is a enter line in Manifest file
For Eg:-
Class-Path: . lib/mail.jar
lib/log4j-1.2.17.jar
lib/poi-3.17.jar
lib/serializer.jar
Main-Class: com.mypack.MyMain
Solution is Make the class path attributes in one line seperated by space like as follows:
Class-Path: . lib/mail.jar lib/log4j-1.2.17.jar lib/poi-3.17.jar lib/serializer.jar
Main-Class: com.mypack.MyMain
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)
I fixed it! 🙂
I was using the Mac program “TextEdit” and that’s why i had the error..
TextWrangler fixed the problem! 😀
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.
YOU ARE MARVELOUS, I HAVE BEEN 2 DAYS SEARCHING FOR THIS ANSWER
Thanks… you saved me sometime! 🙂