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

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

问题描述

我有一个java项目在Eclipse中运行时工作得很好。当我尝试将其导出为JAR文件Runnable JAR文件 .jar文件是创建,但是当我双击它来尝试运行程序,它给我一个错误,说

 无法找到主类:package.MainClassName。程序将退出。 

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

 清单版本:1.0 
主类:package.MainClassName
(空行)

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



实际的程序不是太复杂 - 这是一个简单的蛇游戏Swing(加上代码都可以在Eclipse内部运行)。



任何想法会导致此错误,以及如何解决?如果还有其他信息,请告诉我。

解决方案

好的,所以我终于得到了。如果我使用JRE 6而不是7,一切都会很好。不知道为什么,但它的作品。


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."

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)

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.

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.

解决方案

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天全站免登陆