java jar 文件不会执行,没有主清单属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17136970/
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
jar file wont execute, no main manifest attribute
提问by LazySloth13
I have the following java classes and text document in a file:
我在文件中有以下 java 类和文本文档:
Board.class
BoardPanel.class
Frame$ActionHandler.class
Frame.class
manifest.txt
Where manifest.txt
contains:
其中manifest.txt
包含:
Main-Class: Frame
But when I type the following commands:
但是当我输入以下命令时:
> jar cvfm gameOfLife.jar manifest.txt *.class
> java -jar gameOfLife.jar
It reports this error:
它报告此错误:
no main manifest attribute, in gameOfLife.jar
Have I got the wrong text in manifest.txt
? Or is my error coming from something else?
我有没有弄错文字manifest.txt
?还是我的错误来自其他方面?
回答by Luiggi Mendoza
The MANIFEST.MFfile must be inside the META-INFfolder of your jar. Refer to this here: Understanding the Default Manifest.
在MANIFEST.MF文件必须在内部META-INF您的罐子文件夹。请参阅此处:了解默认清单。
Note that having a manifest.txtfile doesn't mean you have a default MANIFEST file. Also, it would be better if you create the MANIFEST file altogether when creating the jar instead of adding it manually after the creation (noted by BrianRoach's comment).
请注意,拥有manifest.txt文件并不意味着您拥有默认的 MANIFEST 文件。此外,如果您在创建 jar 时完全创建 MANIFEST 文件而不是在创建后手动添加它会更好(BrianRoach 的评论指出)。
To update the MANIFEST file contents, follow the Oracle tutorial: Modifying a Manifest File.
要更新清单文件内容,请遵循 Oracle 教程:修改清单文件。
回答by Vishal K
Put a new line in end in your manifest.txt
file . Look at Setting an Application's Entry Point. It says that:
在您的manifest.txt
文件中添加一个新行。查看设置应用程序的入口点。它说:
Warning: The text file must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return.
警告:文本文件必须以换行或回车结束。如果最后一行没有以新行或回车结束,则不会正确解析。
The content of your manifest.txt
should be:
你的内容manifest.txt
应该是:
Main-Class: gameOfLife.Frame
(Don't forget to add new line in manifest file).Now keep this manifest.txt
file just outside gameOfLife
folder. Thereafter, on command prompt just move one directory up of gameOfLife
. For example if your gameOfLife
is in c:\apps\gameOfLife
then on command prompt it should be:
(不要忘记在清单文件中添加新行)。现在将此manifest.txt
文件保留在gameOfLife
文件夹之外。此后,在命令提示符下只需将一个目录向上移动gameOfLife
. 例如,如果你gameOfLife
就是在c:\apps\gameOfLife
随后的命令提示符下它应该是:
C:\apps>jar -cvfm gameOfLife.jar manifest.txt gameOfLife/*.class