Java程序仅在IDE中运行,而不是作为Jar导出 [英] Java Program only runs in IDE, not exported as a Jar

查看:97
本文介绍了Java程序仅在IDE中运行,而不是作为Jar导出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在我的IDE中运行我的软件而没有任何问题,但是当我尝试将其编译到jar中并尝试运行它时,它表示无法找到主类。过去我成功地使它完美地工作了几次,但我不久前发现了这个问题,所以我不知道什么时候出错了。
jar有一个META-INF,所有设置都正确,就像我的旧版本一样,主要类就在那里。其他人也无法编译,所以这不仅仅是我。代码在Github上,因此可以帮助我解决这个问题。

I can run my software without any problems in my IDE, but when I try to compile it to a jar, and try to run it, it says that the main class can't be found. I succeeded to make it work perfectly several times in the past, but I found this problem few time ago, so I can't really know when it went wrong. The jar has a META-INF, all properly set up, like in my older versions, and the main class is there. Other peoples can't compile too, so it's not just me. The code is on Github, so that could be a tool to help me solve this.

但我想知道,只是通过阅读本文,是否有一些常见的错误可能导致这种情况,或者这种情况并不常见?

But I want to know, just by reading this, is there some common mistakes that could cause this, or this is uncommon?

编辑:
我正在使用IntelliJ IDEA
,我将检查版本是否相同。

I'm using IntelliJ IDEA and I will check if the versions are the same.

EDIT2:
他们确实拥有相同的版本,它正在导出一个可执行jar,其中定义了正确的主类,正如我以前所有版本所做的那样。

They do have the same version, and it's exporting an executable jar with the correct main class defined, as I have beeing doing for all the previous versions.

推荐答案

检查jar文件的META-INF文件夹中是否存在MANIFEST.MF,并确保该行:

Check that the MANIFEST.MF is present in the META-INF folder of the jar, and make sure that the line :

Main-Class: yourMainClass

出现在文件中,然后确保使用以下命令行启动jar:

is present inside the file, then make sure that you start the jar with this command line :

java -jar yourjar.jar

您是否尝试启动指定主类的jar文件?例如:

Have you tried to launch the jar file specifying the main class ? For example :

java yourjar.jar yourMainClass

它是否以这种方式工作?

Does it work in this way ?

这篇关于Java程序仅在IDE中运行,而不是作为Jar导出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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