java jar文件“无主要清单属性”

发布于 2025-01-27 02:24:43 字数 1244 浏览 1 评论 0原文

首先,我研究了有关此主题的类似问题。我还没有找到解决方案。

我希望分发一个我一直在研究的小型项目。麻烦是我不能指望他们所有人都能运行.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疯了 2025-02-03 02:24:43
jar cfe Hello.jar Hello Hello.class Hello.java

会为你做。您需要将-e参数指向主类,以便jar知道如何使其可执行。这比制作自己的清单要容易

jar cfe Hello.jar Hello Hello.class Hello.java

will do it for you. You need to point the -e parameter to the main class so that jar knows how to make it executable. This is easier than making your own manifest

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文