创建 .jar 文件 - 获取“无法找到主类”即使使用带有回车符的manifest.txt

发布于 2024-10-28 16:37:33 字数 543 浏览 6 评论 0原文

我正在尝试创建我的第一个 jar 文件,但遇到了麻烦。我正在使用 DOS 来执行此操作,并且我的路径和所有内容都设置正确。

这些是我试图包含的文件: 机器人类 开始.class 停靠等级 Thread.class

我创建了一个清单文件,看起来像这样(它的末尾也有一个回车符)

Main-Class: Bot

这是我通过DOS运行的

jar cf Bot.jar Manifest.txt Bot.class Start.class Stop.class Visit.class

它成功创建了jar,但是当我尝试执行它时,要么通过单击它或使用命令提示符,

Could not find the main class: Bot. Program will exit.

我尝试在清单文件中使用 Bot 和 Bot.class,但仍然遇到相同的错误。我只尝试将清单文件的扩展名更改为 .mf 而不是 .txt

提前感谢您的帮助!

I'm trying to create my first jar file and I'm having trouble. I'm using the DOS to do it and my path and everything are all set up correctly.

These are the files I'm trying to include:
Bot.class
Start.class
Stop.class
Thread.class

I've created a manifest file that looks like this (it also has a carriage return at the end)

Main-Class: Bot

Here is what I'm running through the DOS

jar cf Bot.jar Manifest.txt Bot.class Start.class Stop.class Visit.class

It creates the jar successfully and but when I try and execute it, either by clicking on it or using the command prompt I get

Could not find the main class: Bot. Program will exit.

I have tried using both Bot and Bot.class in the manifest file but still get the same error. I've only tried changing the extension on the manifest file to .mf instead of .txt

Thanks in advance for your help!

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

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

发布评论

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

评论(2

梦途 2024-11-04 16:37:33
jar cmf Manifest.txt Bot.jar Bot.class Start.class Stop.class Visit.class

需要 m 开关来告诉 jar 哪个文件是清单。请注意,mf 的顺序必须与 Manifest.txtbot.jar 的顺序一致,

请记住jar 中的目录结构必须与您的包结构相匹配。

例如,对于 package com.me.Bot 添加的文件应该是 com/me/Bot.class 而不仅仅是 Bot.class

jar cmf Manifest.txt Bot.jar Bot.class Start.class Stop.class Visit.class

The m switch is needed to tell jar which file is the manifest. Note that the order of m and f must match the order of Manifest.txt and bot.jar

Remember that the directory structure in the jar must match your package structure.

e.g. for package com.me.Bot the added file should be com/me/Bot.class not just Bot.class

天涯沦落人 2024-11-04 16:37:33

学习如何手动构建 jar 一次是一件很有趣的事情。然而,从长远来看,我建议学习构建工具(antmaven,无论如何)。

learning how to manually build a jar is a fun thing to do once. for the long term, however, i'd recommend learning a build tool (ant, maven, whatever).

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