1

I followed some online tutorial and build a little GUI. I tried to make a jar file by clean and build project in the Netbeans, but the jar file doesn't let me open for some reason. Am i missing other stuff?

okay here is what happens after i type in java -jar GUI2.jar

Exception in thread "main" java.lang.UnsupportedClassVersionError: gui2/GUI2 : U nsupported major.minor version 51.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(Unknown Source) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source)at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$000(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) Could not find the main class: gui2.GUI2. Program will exit
jmj
  • 237,923
  • 42
  • 401
  • 438
Bango
  • 288
  • 2
  • 14
  • try running it from terminal and paste the exception/error message here – jmj Jul 22 '13 at 19:56
  • how do i run jar file on cmd? – Bango Jul 22 '13 at 19:58
  • `java -jar /path/to/yourJar.jar` – jmj Jul 22 '13 at 19:58
  • Exception in thread "main" java.lang.UnsupportedClassVersionError: gui2/GUI2 : U nsupported major.minor version 51.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(Unknown Source) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) – Bango Jul 22 '13 at 20:03
  • Check, whether your manifest file in .jar file has a proper main class – DRastislav Jul 22 '13 at 20:04
  • at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$000(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) Could not find the main class: gui2.GUI2. Program will exit – Bango Jul 22 '13 at 20:04
  • 1
    please edit your question to include this trace with proper formatting – jmj Jul 22 '13 at 20:05
  • And please dont put output in comment - please edit your question + output, it will be more readable – DRastislav Jul 22 '13 at 20:05

3 Answers3

1

If you want to execute a JAR file, you can run from command line "java -jar yourJarFilePathHere".

Also, take a look at this SO post...

https://stackoverflow.com/a/5258323/1246574

Community
  • 1
  • 1
Jim
  • 6,753
  • 12
  • 44
  • 72
0

Unsupported major.minor version 51.0

This tells that runtime environment doesn't support the format of class compiled

Either upgrade JRE to supported version or compile your source with runtime environment compatibility by adding -source switch

For netbeans: right click on project > properties > source select the source version compatible with your runtime version (java -version from terminal where you are running it) and rebuild the jar

jmj
  • 237,923
  • 42
  • 401
  • 438
  • after i installed the JRE from the offical site it works now, but for some reason i cant run it on the terminal. same error pops up. – Bango Jul 22 '13 at 20:16
  • it prints out the same error message in the as i stated earlier and i have no clue what do you mean by selecting the source version compatible with my runtime version :( – Bango Jul 23 '13 at 04:04
0

The problem is that when you compile a java file it targets a certain version of Java (1.6, 1.7, etc). So if you compile your project for version 1.7, but on your computer you only have installed 1.6, it will give you this Unsupported major.minor version error when you try to run it. That just means there's a mismatch between the target version and the installed version.

The solution: check the Java version currently installed on your computer with java -version from the command line. I would just go ahead and update to be safe. Then check the target in your Netbeans settings (right click your project name -> Properties -> Sources -> Source/Binary format)

Sevy
  • 688
  • 4
  • 11