java 使用 jar 进行归档时头文件无效
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/419314/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
invalid header file while using jar for archiving
提问by arshad
When i use this cmd line : jar cmf arshad.mf ars.jar *.class i get this error :
当我使用此 cmd 行时:jar cmf arshad.mf ars.jar *.class 我收到此错误:
invalid header field name:Manifest-version
This is my manifest file :
这是我的清单文件:
Manifest-Version: 1.0
Main-Class:t
i made the manifest file with notepad in UTF-8 encoding - is there any problem with the manifest ?
我用 UTF-8 编码的记事本制作了清单文件 - 清单有问题吗?
回答by Adam Rosenfield
Add a space after the colons:
在冒号后添加一个空格:
Manifest-Version: 1.0
Main-Class: t
回答by Angel_DongJie
Yes,it is true.
是的,它是真的。
A common mistake people make when writing their manifest files for jar's is that they don't put spaces after their colons. I don't know, based on what you wrote here, if that's it or not but give it a try.
人们在为 jar 编写清单文件时犯的一个常见错误是他们没有在冒号后放置空格。我不知道,根据你在这里写的内容,如果是这样,但试一试。
Example:
例子:
Main-Class:someClass //wrong
Main-Class: someClass //correct
回答by CodeOwl
Also, your manifest file must be saved as UTF-8. You're not necessarily safe writing it on MS Notepad and saving as UTF-8 encoding. This post has some good details:
此外,您的清单文件必须另存为 UTF-8。您不一定安全地将它写在 MS 记事本上并保存为 UTF-8 编码。这篇文章有一些很好的细节:
Invalid Header Field Name when adding manifest to JAR using Eclipse
使用 Eclipse 将清单添加到 JAR 时出现无效的标头字段名称
Notepad adds some bytes onto the front to broadcast the endian-ness of the data. This will break the jar command. A decent solution is to not use Notepad and download Notepad++. In Notepad++ you select 'encoding' from the top bar, and select 'UTF-8 Without BOM'. Saving your manifest file with this setting applied should solve the problem. If there are no others.
记事本在前面添加一些字节以广播数据的字节序。这将破坏 jar 命令。一个不错的解决方案是不使用记事本并下载 Notepad++。在 Notepad++ 中,您从顶部栏中选择“编码”,然后选择“无 BOM 的 UTF-8”。应用此设置保存清单文件应该可以解决问题。如果没有其他人。

