java.lang.UnsupportedClassVersionError: Unsupported major.minor version 52.0 when running JAR

8

I have a project in NetBeans and I have to pass it to test for other users. I'm running it on Ubuntu 14 and running the following command to run .jar:

java -jar "TesteTableYasc.jar"

However, trying to run the .jar file gives Java version error. The error is as follows:

 Exception in thread "main" java.lang.UnsupportedClassVersionError:     yasc/Main : Unsupported major.minor version 52.0
     at java.lang.ClassLoader.defineClass1(Native Method)
     at java.lang.ClassLoader.defineClass(ClassLoader.java:803)
     at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
     at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
     at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
     at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
     at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
     at java.security.AccessController.doPrivileged(Native Method)
     at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
     at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)

When you run java -version :

java version "1.7.0_111"
OpenJDK Runtime Environment (IcedTea 2.6.7) (7u111-2.6.7-0ubuntu0.14.04.3)
OpenJDK Client VM (build 24.111-b01, mixed mode, sharing)

When you run javac -version :

javac 1.6.0_40

How can I resolve this error?

    
asked by anonymous 09.11.2016 / 20:46

1 answer

2

The first problem is related to the version of java used to compile the jar. In this case, the jar was compiled with version 1.8 and is trying to run it with a lower version. Depending on dependencies, you can either build the jar with compatibility for a lower version or run the jar with version 1.8 of java.

  • J2SE 8 = 52
  • J2SE 7 = 51
  • J2SE 6.0 = 50
  • J2SE 5.0 = 49
  • JDK 1.4 = 48
  • JDK 1.3 = 47
  • JDK 1.2 = 46
  • JDK 1.1 = 45

Regarding the theme of versions 1.6 and 1.7, the theme seems to be related to having two entries in the path. As you are using Ubuntu you can use the following command to configure the java version

sudo update-alternatives --config java
    
15.01.2017 / 22:39