java jar文件“无主要清单属性”
首先,我研究了有关此主题的类似问题。我还没有找到解决方案。
我希望分发一个我一直在研究的小型项目。麻烦是我不能指望他们所有人都能运行.class文件。因此,我正在尝试生成一个.jar文件,我可以将其变成.exe文件。但是,我遇到了一个问题。它抱怨缺少主要清单属性。经过一番谷歌搜索,我决心尝试一点 nofollow noreferrer“> tutorial 。我正在关注教程(甚至下载Little Hello.jar文件),但我仍然没有主要的清单属性。
当我运行Windows 10时,我正在使用PowerShell运行命令。这是我运行的命令:
PS C:\testJarFraNettet> javac Hello.java
PS C:\testJarFraNettet> jar cmf Hello.mf Hello.jar Hello.class Hello.java
PS C:\testJarFraNettet> java -jar Hello.jar
no main manifest attribute, in Hello.jar
PS C:\testJarFraNettet>
您还会注意到我也将.java文件包含在.jar中,以确保。
Hello.mf包含:
Manifest-Version: 1.0
Main-Class: Hello
我研究了生成的.jar文件。内部,在命令中指定的文件中,我找到了预期的。\ meta-inf \ subest.mf文件,带有以下内容:
Manifest-Version: 1.0
Created-By: 17.0.1 (Eclipse Adoptium)
我从未触摸Eclipse(我使用VS代码),但是我认为这绝对没有后果。 根据我在网上找到的另一篇文章,我编辑了该文件,而是包含教程告诉我应该包含的内容:
Manifest-Version: 1.0
Main-Class: Hello
仍然没有运气。我决定不显示自己的代码,因为无论如何我都会遇到相同的错误,因此不必要的故障排除变得复杂。我还有一些障碍,例如如何添加图像文件。该项目是基于GUI的游戏。但这是稍后的问题。
谢谢您的宝贵时间!
To start, I have looked at the similar questions posted about this topic. I have not found a solution.
I wish to distribute a small project I have been working on to friends and family. Trouble is I can't expect them all to be able to run .class files. Therefore I am trying to produce a .jar file that I can turn into an .exe file. I am however running into an issue. It complains about missing the main manifest attribute. After some googling, I resolved to try a little tutorial. I am following the tutorial (even downloading the little Hello.jar file), but still I get no main manifest attribute.
As I am running Windows 10, I am using PowerShell to run commands. This is the commands I've run:
PS C:\testJarFraNettet> javac Hello.java
PS C:\testJarFraNettet> jar cmf Hello.mf Hello.jar Hello.class Hello.java
PS C:\testJarFraNettet> java -jar Hello.jar
no main manifest attribute, in Hello.jar
PS C:\testJarFraNettet>
You'll notice I've included the .java file in the .jar as well, just to be sure.
Hello.mf contains:
Manifest-Version: 1.0
Main-Class: Hello
I investigated the .jar file that gets produced. Inside, among the files specified in the command, I find the expected .\META-INF\MANIFEST.MF file with the following content:
Manifest-Version: 1.0
Created-By: 17.0.1 (Eclipse Adoptium)
I've never touched Eclipse (I use VS Code), but I assume this is of no consequence.
Per another article I found online, I edited the file to instead contain what the tutorial tells me it should contain:
Manifest-Version: 1.0
Main-Class: Hello
Still no luck. I've decided against showing my own code, as it needlessly complicates troubleshooting since I get the same error anyways. I still have some hurdles left, such as how to add image files. The project is a GUI based game. But that is an issue for later, I suppose.
Thank you for your time!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
会为你做。您需要将
-e
参数指向主类,以便jar
知道如何使其可执行。这比制作自己的清单要容易will do it for you. You need to point the
-e
parameter to the main class so thatjar
knows how to make it executable. This is easier than making your own manifest