Creating Jar file - doesn't work on other computers

﹥>﹥吖頭↗ 提交于 2019-12-07 04:59:07

问题


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?


回答1:


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 from 1.7 down to 1.6.

Edit: I've also encountered this error on computers with JVM 7.




回答2:


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 of start as a classname).

Another common issue is that the last line of the MANIFEST.MF file is uninterpreted, as stated in the Java tutorial:

Warning:

The 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.



来源:https://stackoverflow.com/questions/9263394/creating-jar-file-doesnt-work-on-other-computers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!