Java无法执行没有主清单属性的jar文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21239936/
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
Java can't execute jar file no main manifest attribute
提问by yeah its me
jar cvef Main.jar Main *
added manifest
adding: DrawPane.class(in = 344) (out= 257)(deflated 25%)
adding: DrawPane.java(in = 306) (out= 175)(deflated 42%)
adding: main(in = 9038) (out= 8275)(deflated 8%)
adding: Main.class(in = 868) (out= 544)(deflated 37%)
adding: Main.java(in = 507) (out= 260)(deflated 48%)
adding: Manifest.txt(in = 18) (out= 18)(deflated 0%)
adding: src/(in = 0) (out= 0)(stored 0%)
adding: src/icon.png(in = 1163) (out= 1168)(deflated 0%)
adding: src/Thumbs.db(in = 3584) (out= 1038)(deflated 71%)
jar file created, then:
创建 jar 文件,然后:
java -jar Main.jar
I get an error:
我收到一个错误:
no main manifest attribute, in Main.jar
what I'am doing wrong?
我做错了什么?
采纳答案by Giovanni Botta
As per this tutorialyour manifest file should have relative path META-INF/MANIFEST.MF
. It doesn't look like you added your own manifest there. The jar
command adds a default manifest, that's why it says 'manifest added'.
根据本教程,您的清单文件应该具有相对路径META-INF/MANIFEST.MF
。看起来您没有在那里添加自己的清单。该jar
命令添加了一个默认清单,这就是为什么它说“已添加清单”。
EDIT: As per the next page in the tutorial, the basic syntax to add content to the manifest file is the following:
编辑:根据教程的下一页,向清单文件添加内容的基本语法如下:
jar cfm jar-file manifest-addition input-file(s)
I recommend to read the first few section of the tutorial and I'm sure you'll get the result you want!
我建议阅读教程的前几节,我相信你会得到你想要的结果!
回答by Pradida
make sure to write 1 space after ":" and new line after class name and save it that way. jar tool syntax:
确保在“:”后写 1 个空格,并在类名后写新行并以这种方式保存。jar 工具语法:
jar -cvmf manifest.txt appname.jar ClassName.class
after running tool , run jar file with
运行工具后,运行 jar 文件
java -jar appname.jar
Content of manifest.txt file
manifest.txt 文件的内容
Main-Class:(1space)ClassName(press enter for new line)
Main-Class:(1space)ClassName(按回车换行)
Hope it helps
希望能帮助到你