Java – Cannot execute Java app on Vista Business – “Cannot find the main class… Program will exit”

executable-jarjavanetbeans6.7windows-vista

I have written a Java GUI app (using Netbeans 6.7) requiring Java 1.6. I successfully run it on my XP PC and also my Mac OSX (10.5.7).

My client is running Vista Business, and cannot run the application by double clicking the jar file. He can execute it from the command line: "javaw -jar …" The error received is: "Cannot find the main class… Program will exit".

I've asked the client to do the following:

  • install the latest JRE
  • run JarFix

I've verified that:

  • JRE is installed in correct location
  • jar file association is correct
  • application works (as I have tested it on XP and Mac OSX, and the client can run it from the command line)

Any ideas on what else I can investigate? Note, Netbeans created the main jar file, and also a lib directory with a couple of other Jarfiles. I've unzipped the jarfile and examined the manifest file (which looks good). The correct main class is also within the app's jarfile.

Does the client need to be careful as to where the application is executed from in Vista?

Thanks very much.
Prembo

Best Answer

Does exactly the same JAR file work on other operating systems?

Is the manifest file (META-INF/MANIFEST.MF) in the JAR file correct? One catch to watch out for is that the manifest file MUST end with an empty line; if it doesn't, the last line in the manifest file will be ignored. So, for example, if the last line in your manifest file is something like this:

Main-Class: com.mypackage.MyProgram

and it is not followed by an empty line, then Java will ignore the line and it will not be able to find the main class of the program.

See Sun's Java Tutorial about deploying Java programs in JAR files for exact details about how to package your application in a JAR; it also contains the warning about the manifest file needing to end with an empty line.

Also, double-check if the right version of Java is used. Are you using the exact same version of Java as on Windows XP? Try:

java -version

to see which Java version is being used.