“找不到主类"错误 [英] "Could not find the main class" error

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

问题描述

我有一个由 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 文件.在另外两台计算机上它工作正常(win 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 必须包含一个适当的 main-方法.此外,必须复制 Class-Path: 行中的所有 jars 引用.

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屋!

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