What is java.io.IOException: invalid header field?

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 is the reason that I get these exceptions?

+6
source share
6 answers

I assume the problem is with your manifest file. See if you have a typo in the header variable name.

+6
source

Make sure your manifest.txt file contains the contents as follows:

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

Note that parsing requires newline / carriage conversion.

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

+1
source

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

0
source

I solved a similar problem. Always the first manifest header makes the JAR an "invalid header" IOException. Therefore, I assume that the utf-8 file specification makes the Jar incomprehensible. Although I think I read somewhere that the manifest file should be encoded in utf-8, I saved my mf file to ANSI using Windows Notepad, and the JAR just stopped complaining about the header name.

0
source

The stupid mistake to do (what I did) was to make jar cvfm manifest.txt myjar.jar *.class instead of jar cvfm myjar.jar manifest.txt *.class

0
source

After all the properties, there should be one empty line in the manifest.txt files, otherwise the properties are not copied to the jar file Ex-Main-class: Myclass / n

0
source

Source: https://habr.com/ru/post/908416/


All Articles