找不到主类,程序将退出
我使用 Windows 7 中的命令提示符创建了一个可执行 jar,
jar cvfm MyJarName.jar manifest.txt *.class
它创建了 .jar 文件。但是,当我尝试打开它时,会出现一个弹出窗口,其中显示“
Could not find the main class: <ClassName>. Program will exit.
使用时
java -jar jarName.jar
然而,当我在命令提示符中 ,它工作正常”。这是怎么回事?我希望能够双击它。
I made an executable jar with the command prompt in Windows 7 using the
jar cvfm MyJarName.jar manifest.txt *.class
which created the .jar file. But when I attempt to open it, I get a pop-up window that says
Could not find the main class: <ClassName>. Program will exit.
Yet, when I use
java -jar jarName.jar
in the command prompt, it works fine. What's the deal? I want to be able to just double-click it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
哈,我发现问题所在了。我使用jdk1.7制作程序,但安装了jre6。我升级到了 jre7,现在它工作正常了:)
该
行在命令提示符下工作,因为我的 java 路径设置为 jdk 文件夹。
Ha, I found what the problem was. I made my program using jdk1.7, but I had jre6 installed. I went and upgraded to jre7, and now it works fine :)
The
line was working in the command prompt because my java path was set to the jdk folder.
如果您使用的是
JDK 1.6
或更高版本,那么您可以通过Jar
工具的e
标志覆盖manifest属性。 (阅读 - 使用 JAR 工具设置入口点):示例:
编译运行Jar工具,
调用app
If you are using
JDK 1.6
or higher then you can override the manifest attribute viae
flag ofJar
tool. (Read - Setting an Entry Point with the JAR Tool):Example:
Compile and run Jar tool,
Invoke app
清单文本文件必须以换行符或回车符结束。如果最后一行不以换行符或回车符结尾,则将无法正确解析它。
The Manifest text file must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return.
我面临着同样的问题。我所做的是右键单击项目->属性,然后从“选择/二进制格式”组合框中选择 JDK 6。然后我进行了清理和构建,现在当我单击 Jar 时,它工作得很好。
I was facing the same problem. What I did is I right clicked the project->properties and from "Select/Binary Format" combo box, I selected JDK 6. Then I did clean and built and now when I click the Jar, It works just fine.
如果您使用较低版本的 Java(例如 Java1.5)构建源文件并尝试使用较高版本的 Java(例如 java 1.6)运行该程序/应用程序,您将遇到此问题。
如需更好的解释,请参阅此链接。 点击此处
if you build the source files with lower version of Java (example Java1.5) and trying to run that program/application with higher version of Java (example java 1.6) you will get this problem.
for better explanation see this link. click here
我在打开 JMeter 4.0 时遇到了这个问题。我固定如下。
我在 Program Files (x86) 文件夹中安装了 JRE 7,在 Program files 文件夹中安装了 JDK 8。所以我只是从机器上卸载了 JRE7。我只保留了最新版本的JDK。它解决了问题。
I got this issue in opening JMeter 4.0. I fixed as below.
I have JRE 7 installed in Program Files (x86) folder and JDK 8 installed in Program files folder. So I just uninstalled JRE7 from machine. I just kept latest version of JDK. It fixed the problem.
提取 jar 并将 jar 内的清单内容与外部清单.txt 进行比较。您很可能会找到问题所在。
Extract the jar and compare the contents of the manifest inside the jar with your external manifest.txt. It is quite possible that you will locate the problem.
检查这样做(在我的机器上工作):
让文件为 x.java
Check out doing this way (works on my machine):
let the file be x.java