如何使用 manifest.mf 包含主类的正确位置?

发布于 2024-10-06 13:20:03 字数 810 浏览 3 评论 0原文

谁能帮我解决这个问题吗?我无法找到任何可以完全满足我需要的答案。我找到的所有答案都与向清单文件添加额外的库有关。

情况是这样的:

我使用 NetBeans 6.9 编写了一个游戏。该游戏是用 Java 语言编写的。大约有80个班级。所有类都包含在默认包中。游戏正确执行。我已经在这个项目上工作了大约 18 个月,并且在开发游戏时我总是维护可执行代码。

我做了什么:

我需要将一些东西从我编写的静态类导入到我正在处理的另一个类中。为了做到这一点,我必须将所有内容从默认包中移出。我使用 NetBeans 将所有内容重构为自定义包。

发生了什么:

当我执行“清理并构建”时,项目构建成功。 当我执行“运行主项目”时,出现以下错误:

java.lang.NoClassDefFoundError:WarMachine
引起原因:java.lang.ClassNotFoundException:WarMachine
...堆栈跟踪
找不到主类:WarMachine。程序将退出。

我检查了 .jar 文件,发现所有已编译的 .class 文件都在那里,包括主类(称为 WarMachine.class)。所有 .class 文件都位于名为 Machine 的目录中(这是我让 NetBeans 将所有内容重构到的包名称)。

根据我在互联网上找到的信息,问题是我的manifest.mf 文件没有指向WarMachine.class 文件的正确位置。

我的清单文件需要说明什么?我不使用任何其他库或类似的东西。我有 78 个类,所有这些都在“Machine”包中。谁能帮助我吗?

感谢您抽出时间!

Can anyone help me with this? I have not been able to find anything that answers this for exactly what I need. All the answers I find have to do with adding additional libraries to manifest files and what not.

Here's the situation:

I have written a game using NetBeans 6.9. The game is in Java. There are about 80 classes. All classes are contained in the default package. The game executes correctly. I've been working on this project for about 18 months and I always maintain executable code as I have developed the game.

What I did:

I needed to import something from a static class I'd written, into another class I was working on. In order to do that, I had to move everything out of the default package. I used NetBeans to refactor everything into a custom package.

What happened:

When I do a "clean and build", the project builds successfully.
When I do a "run main project", I get the following error:

java.lang.NoClassDefFoundError: WarMachine

Caused by: java.lang.ClassNotFoundException: WarMachine
...stack trace
Could not find the main class: WarMachine. Program will exit.

I have checked the .jar file and I see that all the compiled .class files are there, including the main class (called WarMachine.class). All the .class files are in a directory called Machine (that was the package name I had NetBeans refactor everything into).

From what I have been able to find on the internet, the problem is that my manifest.mf file does not point to the correct location of the WarMachine.class file.

What does my manifest file need to say? I don't use any other libraries or anything like that. I have 78 classes, all of which are in the "Machine" package. Can anyone help me?

Thanks for your time!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

椵侞 2024-10-13 13:20:04

您必须告诉 Netbeans 主类文件在哪里。右键单击您的项目,选择“属性”,然后转到左侧的“运行”树元素。

现在,右侧将有一个“主类”文本框。单击“浏览”并选择您的主课程。然后 Netbeans 应该会为您修复清单文件。

运行属性屏幕截图

如果您好奇,dist 文件夹的 .jar 文件中的清单文件应包含如下行this:

Main-Class: Machine.WarMachine

顺便说一句,使用小写字母作为包名称被认为是标准做法。您应该调用您的包machine

You have to tell Netbeans where the main class file is. Right click on your project, select "Properties", then go to the "Run" tree element on the left.

You will now have a "Main Class" textbox on the right. Click "Browse" and select your main class. Netbeans should then fix the manifest file for you.

Run properties screenshot

In case you are curious, your manifest file inside the .jar file of the dist folder should have a line like this:

Main-Class: Machine.WarMachine

As an aside, it is considered standard practice to use lowercase letters for package names. You should call your package machine.

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