创建 .jar 文件 - 获取“无法找到主类”即使使用带有回车符的manifest.txt
我正在尝试创建我的第一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
需要
m
开关来告诉jar
哪个文件是清单。请注意,m
和f
的顺序必须与Manifest.txt
和bot.jar
的顺序一致,请记住jar 中的目录结构必须与您的包结构相匹配。
例如,对于
package com.me.Bot
添加的文件应该是com/me/Bot.class
而不仅仅是Bot.class
The
m
switch is needed to telljar
which file is the manifest. Note that the order ofm
andf
must match the order ofManifest.txt
andbot.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 becom/me/Bot.class
not justBot.class
学习如何手动构建 jar 一次是一件很有趣的事情。然而,从长远来看,我建议学习构建工具(ant,maven,无论如何)。
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).