35

When I try running my java .jar on another machine I get the error

Unsupported major.minor version 52.0

I compiled my program using the jdk 1.6 and my machine (separate one) has java 7 installed.

This is the java version my machine is running:

java version 1.7

Here are the settings in my IDE (Eclipse Lunar)

eclipse compiler settings

eclipse JRE settings

Why am I still getting an unsupported error?

I did check my run configuration and change it to jre6, but when I do I can't even run my program in the IDE.

Note: I would like my program to work with jdk 6, if that is not possible jdk 7.

My Class Path:

class path

Kevin Panko
  • 8,356
  • 19
  • 50
  • 61
Maple
  • 363
  • 1
  • 3
  • 5

13 Answers13

33

I agree with chrylis: you believe you changed your project's compliance settings but probably you didnt.

Right click on your project and:

  • Java / Build Path : Go to Libraries tab and ensure yourself that you are really using jre6
  • Java / Compiler : Ensure yourself that you have selected 1.6 compliance

By the way you can "tell" eclipse that jre8 is 1.6 compliance clicking on Window/Preferences/Java/Installed JREs/Execution Environment and selecting in the left panel, Execution Environments, JavaSE-1.6 and in the Compatible JRE's panel, jre8

Facepalmed
  • 751
  • 12
  • 14
14

Hi I found this link that helped me understand the issue. Hope it is useful. Version released so far are

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

and from thata data it simply means

Many people think why do you get a version mismatch error if Java is backward compatible. Well, its true that Java is backward compatible, which means you can run a Java class file or Java binary (JAR file) compiled in lower version (java 6) into higher version e.g. Java 8, but it doesn't mean that you can run a class compiled using Java 7 into Java 5, Why? because higher version usually have features which are not supported by lower version.

Sometimes you may have more than one version of Java installed in you machine. Make sure the application you are running is pointing to the right or highest version available.

Bryida
  • 482
  • 6
  • 9
2

I Encounter similar issue while doing development on Android Studio 2.2.

My Machine Configuration -

  1. JDK version 1.7.0_79 installed
  2. JDK version 1.8.0_101 installed
  3. Environment variable contains : JAVA_HOME = 1.7.0_79 JDK path and same is added to path variable
  4. Project SDK Location = C:\Program Files\Java\jdk1.8.0_101

I then made below changes - 1. Uninstall JDK 1.7.0_79 2. Updated JAVA_HOME = 1.8.0_101 JDK path (Similar to SDK Location)

Now i am able to compile and run my application successfully , no more Unsupported major.minor version 52.0 Error

Sabextc10
  • 51
  • 4
1

If you are trying to execute your program/application from the command prompt. Just make sure to restart your cmd after you have changed the JAVA_HOME var. Very simple but easily missed sometimes.

sgX
  • 696
  • 1
  • 8
  • 16
0

Several possiblies that causes this problem. The root cause is mismatched of compiler version between projects and IDE. For windows environment you can refer to this blog to do the detail troubleshooting.

ct.tan
  • 2,355
  • 1
  • 11
  • 4
0

The error happens when you have compiled with higher version of Java and it is been tried to run with lower version of JRE. Even with minor version mismatch you would have this issue

I had issue compiling with JDK 1.8.0_31 and it was run with jdk1.8.0_25 and was displaying the same error. Once either the target is updated to higher version or compiled with same or lesser version would resolve the issue

0

Are you using retrolambda? If so, just do JAVA_HOME=$JAVA8_HOME.

Source: https://github.com/evant/gradle-retrolambda/issues/74

espinchi
  • 9,144
  • 6
  • 58
  • 65
0

Its a silly problem, just make sure that the jdk and jre are latest version. This problem mainly occurs due to the automatic update of java(jre) and the jdk is not supported to that version, this makes problem.

Abhijith
  • 9
  • 2
0

Right Click on Project, Properties ---> Java Compiler ( on same page change compiler Compliance Level to 1.6 (or) 1.7 (or) 1.8 ( match with your JAVA_HOME)

0

First of all thank you for all above answers. However, I use Intellij Idea for daily basis. So, I hope my answer will help others.

Run your favourite terminal or command line. Then check your java version by running command

java -version

Then in Intellij press

Ctrl+Alt+Shift+S

in the

Project Settings

tab under

Project SDK

choose appropriate java version. Lastly, rerun your code.

Esmaeil MIRZAEE
  • 1,110
  • 11
  • 14
0

I had also same issue. I solved this problem by updating my system jdk. Previously i used jdk7.0 and now it is updated to jdk8.0. find below link to download the updated jdk with new version. it help me to solve my problem.

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Pravin Ghorle
  • 606
  • 7
  • 7
0

I also had to update the version of Tomcat I was using from Tomcat 7 to Tomcat 8.

TheBakker
  • 2,852
  • 2
  • 28
  • 49
0

I had the same issue. Turned out I used some external jars (apache poi 4.1.2) which were compiled with 1.8. Solved it by changing Java Build Path JRE to 1.8.

Chen Ni
  • 979
  • 1
  • 12
  • 24