“找不到主类"运行 Eclipse 导出的 jar 时出错 [英] "Could not find the main class" error when running jar exported by Eclipse

查看:37
本文介绍了“找不到主类"运行 Eclipse 导出的 jar 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Java 项目,在 Eclipse 中运行它时运行良好.当我尝试将其导出到 "JAR 文件""Runnable JAR 文件" 时,会创建 .jar 文件,但是当我双击它以尝试运行程序它给了我一个错误,说

I have a java project that works perfectly fine when running it from within Eclipse. When I try to export it to either a "JAR file" or "Runnable JAR file" the .jar file is created, but when I double click on it to try to run the program it gives me an error that says

"Could not find the main class: package.MainClassName. Program will exit."

正如我提到的,我尝试导出到两个 JAR 选项,我指定了 main 方法所在的正确类,当我查看 .jar 文件中的实际文件时,一切似乎有序 - 清单看起来像:

As I mentioned, I tried exporting to both JAR options, I specified the correct class that the main method is in, and when I look through the actual files in the .jar file everything seems to be in order -- the manifest looks something like:

Manifest-Version: 1.0
Main-Class: package.MainClassName
(blank line)

并且位于 META-INF 文件夹中.有一个包含我的包名称的文件夹,其中包含所有 .class 文件,包括包含 main 方法的类.我使用的一些图像和文本文件也出现在 jar 文件中.

and is in the META-INF folder. There is a folder with my package name, which contains all the .class files, including the class that contains the main method. A few image and text files that I use also appear in the jar file.

实际的程序并不太复杂——它是一个使用 Swing 的简单贪吃蛇"游戏(加上从 Eclipse 内部运行时所有代码都可以运行).

The actual program isn't anything too complicated -- it's a simple "snake" game using Swing (plus the code all works when run from inside Eclipse).

任何想法是什么导致了这个错误以及我如何解决它?如果我还需要提供任何其他信息,请告诉我.

Any ideas what is causing this error and how I can fix it? Let me know if there's any other information I should provide.

推荐答案

好的,我终于让它工作了.如果我使用 JRE 6 而不是 7,一切都很好.不知道为什么,但它有效.

Ok, so I finally got it to work. If I use the JRE 6 instead of 7 everything works great. No idea why, but it works.

这篇关于“找不到主类"运行 Eclipse 导出的 jar 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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