无法在 Windows 上运行我的 jar 文件
我有这些文件 board.class
和 x4.class
(x4.class 有 main() 方法)。
为了 jar 这些文件,我编写
jar cf x4.jar *.class
并获得了一个 x4.jar
文件。
我将此 x4.jar 文件复制到我的桌面(在 Windows Vista 上)并双击它。我收到此错误:
无法加载主类清单 属性来自
C:\Users\eSKay\Desktop\x4.jar
我应该怎样做才能使该文件作为 jar 可执行文件运行(无需安装任何软件)?
更新: 我使用清单文件来解决该问题。我已经得到了我需要的 jar 文件,如果你这样做的话,它运行得很好:
java -jar x4.jar
但是,当我双击 x4.jar 时没有任何反应,我检查了任务管理器,发现 javaw.exe 正在后台启动,但它是没有显示原始程序给出的输出。
问题可能是什么?
I have these files board.class
and x4.class
(x4.class has main() method).
To jar these files, I wrote
jar cf x4.jar *.class
and got a x4.jar
file.
I copied this x4.jar file to my Desktop (on windows Vista) and double-clicked it. I am getting this error:
Failed to load Main-Class manifest
attribute fromC:\Users\eSKay\Desktop\x4.jar
What should I do to make this file run as a jar executable (without installing any software)?
UPDATE:
I used a manifest file to fix the problem. I have got the jar file I needeed and it is running fine if you do:
java -jar x4.jar
But, when I double click x4.jar nothing happens, I checked Task Manager and found that a javaw.exe is being started in the background, but it is not showing the output the original program was giving.
What can the problem be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要创建一个 清单文件 其中包含 指定其入口点。然后使用 jar 命令中的“m”标志来指定它。例如,您可能有一个名为manifest.txt的文件:
请注意,文件末尾需要有一个空行,否则
jar
工具将无法正确处理它,忽略最后的默默地。然后运行:
要测试它,请运行:
You need to create a manifest file which contains the
Main-Class
attribute to specify its entry point. Then use the "m" flag in the jar command to specify it. For example, you might have a file called manifest.txt:Note that you need to have an empty line at the end of the file, or the
jar
tool won't process it properly, ignoring the final line silently.Then run:
To test it, run:
我认为@Jon 是正确的,只需确保以 CR/LF 结束文件即可。
设置应用程序的入口点
或者你可以让jar程序自动为你创建Main-Class属性。
I think @Jon is correct, just make sure you end the file with a CR/LF.
Setting an Application's Entry Point
Or you can let the jar program automatically create the Main-Class attribute for you.