我正在尝试将我的程序打包成 JAR 文件,以便可以在多台计算机上使用。
我的程序由 start.java
、userinterface.java
和 writer.java
组成。
该程序是用 Eclipse 编写的,在我的计算机上运行得很好。导出后,它可以在我的计算机上运行,但在其他计算机上会导致以下错误:
“无法找到主类:启动。程序将退出”。
再次,我的程序在我的计算机上运行良好我双击它。
我尝试通过命令提示符创建 JAR 文件,并且我的清单文件是正确的。怎么了?
I'm trying to package my program into a JAR file so it can be used on multiple computers.
My program is composed of start.java
, userinterface.java
and writer.java
.
The program, written in Eclipse, works perfectly on my computer. When exported, it will work on my computer but cause the following error on other computers:
"Could not find the main class: start. Program will exit".
Again, my program runs fine on my computer when I double click on it.
I've tried creating the JAR file via command prompt, and my Manifest file is correct. What is happening?
发布评论
评论(2)
这是一个非常奇怪的bug,我也遇到过。
假设您使用的是
JRE 1.7
,我发现此问题的唯一解决方法是将项目的
JRE
版本从1.7
更改为1.6
。编辑:我在使用 JVM 7 的计算机上也遇到过此错误。
This is a very strange bug which I've also encountered.
Assuming you are using
JRE 1.7
,The only fix I found to this problem was to change the project's
JRE
version from1.7
down to1.6
.Edit: I've also encountered this error on computers with JVM 7.
我相信这是因为您尝试为
Main-Class
属性指定默认包中的类文件。 JAR 文件和默认包并不能很好地混合。我建议将整个项目放入一个简单的包中(据我从附加的 JAR 文件中看到,您仅使用默认包)。另外,尝试采用常见的Java约定(很难说什么是类,首先我认为存在一些特定于包的错误,即使用
Start
而不是start
作为类名)。另一个常见问题是 MANIFEST.MF 文件的最后一行未解释,如 Java 教程中:
I believe it is because you try to specify a class file from the default package for the
Main-Class
attribute. JAR files and default packages don't really mix well. I would advise to put your whole project into a simple package (as far as I saw from the attached JAR file you use only the default package).Also, try to adopt to the common Java conventions (its hard to tell what is a class and first I thought there is some package-specific error, i.e., use
Start
instead ofstart
as a classname).Another common issue is that the last line of the
MANIFEST.MF
file is uninterpreted, as stated in the Java tutorial: