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

Asked

Viewed 3,889 times

8

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

java -jar "TesteTableYasc.jar"

However, when trying to run the file . jar 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 executing 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 executing javac -version:

javac 1.6.0_40

How can I fix this mistake?

  • You seem to be mixing various concepts and heading straight for the solution to what you assume is the problem. I’m suspecting that this is a XY problem. It would be more productive to start from the beginning: how are you running this JAR? What error do you receive?

  • I updated the question

  • 1

    Run on the terminal java -version and javac -version and paste in the question the result of both.

  • I put in question the exit of the commands

  • The build path of your IDE must be pointing to Java 8. Switch to Java 7.

1 answer

2

The first problem is related to the version of java used to compile the jar. In this case, the jar has been compiled with version 1.8 and is trying to run it with a lower version. Depending on the dependencies, you can 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 the fact that it has two path entries. Since you are using Ubuntu you can use the following command to configure the java version

sudo update-alternatives --config java

Browser other questions tagged

You are not signed in. Login or sign up in order to post.