且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

“找不到主类”运行由Eclipse导出的jar时出错

更新时间:2022-10-22 18:57:33

好的,所以我终于得到了。如果我使用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.