Java IOException: '无效的头字段;使用清单创建 .jar 文件时
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18907695/
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
IOException: 'Invalid header field; when creating .jar file with manifest
提问by grim_v3.0
When I type jar cvfm file_name.jar manifest.txt *.class in command prompt I get this error:
当我在命令提示符下键入 jar cvfm file_name.jar manifest.txt *.class 时,我收到此错误:
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:172)
at sun.tools.jar.Main.main(Main.java:1177)
I've never gotten this error before and I can't find anything on it, what does it mean?
我以前从来没有遇到过这个错误,我找不到任何关于它的东西,这是什么意思?
采纳答案by Ragavan
Check the name of a header variable in the MANIFEST file. MANIFEST file is not correct.
检查 MANIFEST 文件中标头变量的名称。MANIFEST 文件不正确。
This tutorial will help to identify the MANIFEST file format and related things, http://docs.oracle.com/javase/tutorial/deployment/jar/manifestindex.html
本教程将有助于识别MANIFEST文件格式和相关的东西,http://docs.oracle.com/javase/tutorial/deployment/jar/manifestindex.html
回答by NRitH
Your Manifest file has to follow the required format. If you're generating the file yourself, then you should be able to figure out where you got the syntax wrong. If the manifest file was generated by some tool or process, however, you'll have to check the tool's documentation to see whether you ran into a bug in the tool.
您的清单文件必须遵循所需的格式。如果您自己生成文件,那么您应该能够找出语法错误的地方。但是,如果清单文件是由某个工具或进程生成的,则您必须检查该工具的文档以查看您是否遇到了该工具中的错误。
回答by Wenjay Chnag
Be careful about the order of the parameters:
注意参数的顺序:
1) jar cvmf manifest.txt some.jar package/*class
2) jar cvfm some.jar manifest.txt package/*class
回答by Megarushing
In case you land here and tried everything and still isn't getting rid of the problem, take a look if there are any accidental tabs instead of 4 spaces for indentation in the MANIFEST file.
如果您登陆这里并尝试了所有方法但仍然没有解决问题,请查看清单文件中是否有任何意外的制表符而不是 4 个空格用于缩进。
I was using a maven pom.xml file to auto-generate the MANIFEST and the property line was too big, spanning multiple lines like this:
我正在使用 maven pom.xml 文件来自动生成 MANIFEST 并且属性行太大,像这样跨越多行:
<Extension-List> item1 item2 item3 item4
item5 item6 item7 item8 <--- these lines are idented with tabs
item9 item10 item11 item12 </Extension-List>
this was corrupting the MANIFEST file in a very hard to see way.
这以一种非常难以察觉的方式破坏了 MANIFEST 文件。
回答by Hyman'
Read carefully the first line of your manifest, for example :
仔细阅读清单的第一行,例如:
Main-Class: main.HelloWorld
I had this error because I added a space like this "Main-Class :"
我有这个错误,因为我添加了一个像这样的空间“Main-Class:”
Maybe it is something similar.
也许它是类似的东西。
回答by Sina Madani
My problem was that I had loads of dependencies on one line so I split it up using a simple Find and Replace where each JAR was on a separate line. It turns out that if you have something like:
我的问题是我在一行上有很多依赖项,所以我使用简单的查找和替换将它拆分,其中每个 JAR 位于单独的行上。事实证明,如果你有类似的东西:
Class-Path: dependencies/org.apache.commons.cli_1.4.jar (note the space at the end)
dependencies/org.apache.log4j_1.2.15.v201012070815.jar (note the space at the end)
You need to make sure that the line doesn't end with a space, and that the new line begins with a space, like so:
您需要确保该行不以空格结尾,并且新行以空格开头,如下所示:
Class-Path: dependencies/org.apache.commons.cli_1.4.jar
dependencies/org.apache.log4j_1.2.15.v201012070815.jar
回答by Tom Rutchik
This problem can also occur if your MANIFEST.MF file begins with some non-printable characters. Tools like notepad and wordpad don't let you see them, so you'll swear you're file looks right and that all your headers are valid.
如果您的 MANIFEST.MF 文件以某些不可打印的字符开头,也会出现此问题。记事本和写字板之类的工具不会让您看到它们,因此您会发誓您的文件看起来正确并且所有标题都是有效的。
In my case I got the message:
就我而言,我收到了以下消息:
java.io.IOException: invalid header field name: ???Built-By
The clue if you are having this situation are those characters occurring before the valid Built-By header. Those are non-printable characters that somehow got into your MANIFEST.MF file. The other clue is to open a command line, navigate to your MANIFEST.MF file and do
如果您遇到这种情况,线索是在有效的 Built-By 标头之前出现的那些字符。这些是不可打印的字符,它们以某种方式进入了您的 MANIFEST.MF 文件。另一个线索是打开命令行,导航到您的 MANIFEST.MF 文件并执行
>cat MANIFEST.MF
??□Build-BY: TSRUT
Bundle-Description: Fragment Controller.
Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
Notice that box character before your 1st header at the beginning of the file. If that's the case, this is the solution to your problem:
请注意文件开头第一个标题之前的框字符。如果是这种情况,这就是您问题的解决方案:
Open up your favorite editor, manual select the entire file (do not use the select-all command, as that will also select those hidden characters). Close the file. Open a new instance of your editor, paste your content, and save the new file back to your original MANIFEST.MF file. Select yes to overwrite. Then verify that those hidden character were removed from the beginning of the file.
打开你最喜欢的编辑器,手动选择整个文件(不要使用全选命令,因为这也会选择那些隐藏的字符)。关闭文件。打开编辑器的新实例,粘贴您的内容,然后将新文件保存回原始 MANIFEST.MF 文件。选择是覆盖。然后验证是否从文件开头删除了那些隐藏字符。
回答by Siva_Munnaluri
if your manifest file is having some additional empty lines will also cause this error . Make sure to remove the additional lines.
如果您的清单文件有一些额外的空行也会导致此错误。确保删除额外的行。