2

Possible Duplicate:
Running Jar file in Windows

I created a .jar file for a small GUI Java project with NetBeans. It runs fine from command line. I have .jar files associated with javaw.exe in the JRE. But when I double click the .jar file I get an error:

Could not find main class. 
Community
  • 1
  • 1
user1830797
  • 75
  • 2
  • 5
  • I wish there was a way to anti-vote to close. This is NOT the same problem as the supposed "duplicate" question. – Stephen C Nov 22 '12 at 11:33

2 Answers2

1

The fact that double clicking is saying that it cannot find the main class means that a JRE is installed. That is NOT the problem. It also means that a suitable shortcut exists. That is NOT the problem ... either.

The problem is (I think) that the JAR file has not been correctly created as an executable JAR file. An executable JAR file must have a Main-class entry in its manifest that tells java.exe or javaw.exe which class contains the "public static void main(String[])" method that is used to start the application. Either the manifest entry is missing, or it refers to a non-existent class.

Since this is your program, you need to take a closer look at the way that you are creating the JAR file. You most likely need to tell NetBeans which class to use as the entry point / "main" class.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
0

check this answer: Running JAR file on Windows.

In all likelihood, you'll need to supply the javaw.exe" -jar "%1" % part in a shortcut, and that will fix the problem.

Community
  • 1
  • 1
Brian Henry
  • 3,161
  • 1
  • 16
  • 17
  • Do that for every Java program I run? There must be a better way. Java isn't brand new. Isn't Java meant to run on many different systems? – user1830797 Nov 17 '12 at 07:37
  • I tried running the jarfix.exe program in the other post. It gives me an error too, saying I do not have a JRE installed. – user1830797 Nov 17 '12 at 08:00