JAR文件:找不到主类 [英] JAR file: Could not find main class

查看:64
本文介绍了JAR文件:找不到主类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我有一个奇怪的问题.我想将一个程序作为.jar文件运行,但是当我双击打开它时,出现一条错误消息,例如找不到主类,程序正在关闭".我很确定我做的一切正确,这个罐子应该可以正常工作.我也尝试过其他程序,每个程序都一样. (我通过BlueJ创建.jar)通过.bat运行它们没有问题.这是所有事情中最奇怪的事情:.jar已经运行了一段时间(我猜是一两个月),我不记得做任何其他事情了.这是相同的BlueJ版本.好的,也许Java更新了,有些东西搞砸了...我用谷歌搜索,但是找不到解决方案. (有些人似乎也有类似的问题,似乎只有他们无法运行他们的.jar文件;他们上传了文件,而其他人则说.jar文件运行正常.)可能是什么问题?我该怎么解决?

Okay, I have a strange problem. I wanted to run one of my programs as a .jar file, but when I open it by double-clicking it, I get an error message like "Could not find main class, program is shutting down". I'm pretty sure I did everything right, the jar should work afaik. I also tried other programs, it's the same with every single one. (I'm creating the .jar's through BlueJ) There is no problem when I run them through a .bat . And here comes the strangest thing of all: The .jar's have worked some time ago (one or two months I guess), and I don't remember doing anything different. It's the same BlueJ-Version. Okay, maybe Java updated and something got messed up... I googled, but I couldn't find a solution. (some people seem to have a similar problem, and it seems to be only them who can't run their .jar's; they uploaded them and other people say the .jar's run fine.) What could be the problem? How can I solve it?

我非常感谢您的帮助. 谢谢:)

I'd really appreciate some help here. Thank you :)

ApertureT3CH

ApertureT3CH

好的,伙计们,你让我不确定.依玛(Imma)在这个邪恶的时间(上午1:34)再次检查清单:P

okay guys, you're making me unsure here. Imma check the manifest again, at this unholy time ( 1:34 am ) :P

这是我的MANIFEST.MF 清单版本:1.0 类路径: 主要类别:LocalChatClientGUI [空行] [空行]

This is my MANIFEST.MF Manifest-Version: 1.0 Class-Path: Main-Class: LocalChatClientGUI [empty line] [empty line]

Main类是正确的.

The Main class is correct.

感谢hgrey:罐子没有问题.我可以从bat文件运行它,实际上与双击jar并没有什么不同,对吧?但是,单击它时我得到了错误,并且它在整个蝙蝠中都可以正常工作.

Thanks to hgrey: There is nothing wrong with the jar. I can run it from a bat file, which actually should not be different from double-clicking the jar, right? Yet I get the error when clicking it, and it works fine through the bat.

我终于解决了这个问题.我重新安装了JRE,现在可以使用,尽管看不到任何版本差异.

I finally solved the problem. I re-installed the JRE and now it works, although I can't see any version differences.

谢谢大家!

推荐答案

当Java运行jar时,它将查看jar的META-INF目录中的manifest.mf文件,并在其中读取MainClass属性.如果未指定,您将得到您所描述的消息.因此,请尝试在罐子中包含正确的manifest.mf.流行的Java构建工具(例如Ant或Maven)支持manifest.mf的生成.

When java runs the jar it will look at manifest.mf file inside the jar's META-INF directory and will read MainClass attribute in there. If it is not specified you will get the message you describe. So, try to include correct manifest.mf into the jar. Generation of manifest.mf is supported by popular java build tools like Ant or Maven.

这篇关于JAR文件:找不到主类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆