“找不到主要类别";错误 [英] "Could not find the main class" error
问题描述
我有一个由Eclipse生成的.jar,我无法在其他计算机上运行(使用Windows XP).出现找不到主类.程序将退出"消息.那台计算机可以在Netbeans生成的另一个.jar上正常运行,所以我认为JRE并不是问题.我更新了JRE,但没有改变.有什么问题吗?
I have a .jar generated by Eclipse, which I cannot run on other computer (with Windows XP). The "Could not find the main class. Program will exit" message appears. That computer runs fine another .jar generated by Netbeans, so it is not a problem with JRE, I guess. I updated JRE but it changed nothing. What is the problem?
更新:我忘了提,我做了一个可运行的jar文件.在另外两台计算机上,它可以正常工作(Windows 7和XP),但在特定计算机上则不能.
UPDATE: I forgot to mention, that I made a runnable jar file. On two another computers it works fine (win 7 and XP), but on that specific one not.
更新2:这是一个Swing应用程序,因此可以通过双击运行JAR.
UPDATE 2: It's a Swing application, so the JAR is run by double-clicking.
推荐答案
检查清单的内容. Main-Class: foo.Bar
行必须与jar文件中的/foo/Bar.class条目相对应,而foo.Bar.java
行必须包含适当的主方法.同样,必须复制Class-Path:
行中的所有jar引用.
Check the contents of the manifest. The Main-Class: foo.Bar
line must correspond to an /foo/Bar.class entry in the jar file, and foo.Bar.java
must contain an appropriate main-method. Also all jars reference in the Class-Path:
line must be copied too.
使用"jar tvf my.jar"查看布局.
Use "jar tvf my.jar" to see the layout.
这篇关于“找不到主要类别";错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!