5

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?

Jared Nielsen
  • 3,669
  • 9
  • 25
  • 36
user1147964
  • 143
  • 2
  • 11
  • 1
    Maybe they have a JVM with a lower version than the one you used to compile? – Guillaume Polet Feb 13 '12 at 15:50
  • Well, I've attached the file to my main post, perhaps you'd care to give it a go? – user1147964 Feb 13 '12 at 15:52
  • If you compiled the program using for example JDK 6, then the program won't be launched by JRE 5. @GuillaumePolet is right: what versions do you use to compile and then run on the other machine ? – Radu Murzea Feb 13 '12 at 15:54
  • OK, I get the same result as your colleagues. I have a JVM 6 but you have compiled using a JVM 7. Either make them upgrade to JVM 7. Or compile using -target 6 – Guillaume Polet Feb 13 '12 at 15:55
  • Maybe, it is not enough memory when running it with the JVM from that computer. It happens a lot in my case. Set the VM arguments for `-Xms` and `-Xmx` when running on that computer. This only applies if the JVM is the same major version. – ecle Feb 13 '12 at 15:58

2 Answers2

5

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.

Acidic
  • 6,154
  • 12
  • 46
  • 80
  • Well, sometimes I would compile projects with `JRE 1.7` and they would work fine, while some other projects encountered the same problem - even though I've tried all of these jars on computers with JVM 7. – Acidic Feb 13 '12 at 15:59
  • 1
    I tried using the -target 6 flag but I get the error: target release 6 conflicts with default source release 1.7. How do I address this? Thank you – user1147964 Feb 13 '12 at 16:00
  • @user1147964 I've used Eclipse to do this, so I am not sure what is the command-line equivalent. I suggest you try doing that using Eclipse. – Acidic Feb 13 '12 at 16:07
  • I just did it using eclipse and it works on the other computer - thanks for the help. Problem is that 1.6 doesn't support HTML in JComponents which is a bit irritating - guess I'll have to force them to update. – user1147964 Feb 13 '12 at 16:10
  • @user1147964 You're welcome. Please mark this as the correct answer if it solved your problem. ^^ – Acidic Feb 13 '12 at 16:11
  • 1
    *"1.6 doesn't support HTML in JComponents"* Of course it does! Swing supported HTML in styled dcouments (`JLabel`, `JEditorPane` ..) since 1.2, when they were first introduced. – Andrew Thompson Feb 13 '12 at 23:53
0

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.

rlegendi
  • 10,466
  • 3
  • 38
  • 50