This question already has answers here:
How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version
(51 answers)
Closed 6 years ago.
Pictures:
Command Prompt showing versions
Picture of error
Hello.java
import java.applet.Applet;
import java.awt.*;
public class Hello extends Applet {
// Java applet to draw "Hello World"
public void paint (Graphics page) {
page.drawString ("Hello World!", 50, 50);
}
}
Hello.html
<HTML>
<HEAD>
<TITLE>HelloWorld Applet</TITLE>
</HEAD>
<BODY>
<APPLET CODE="Hello.class" WIDTH=300 HEIGHT=150>
</APPLET>
</BODY>
</HTML>
Error
Hello : Unsupported major.minor version 52.0
What may the problem be?
The issue is because of Java version mismatch. Referring to the JVM specification the following are the major versions of classfiles for use with different versions of Java. (As of now, all versions support all previous versions.)
Java SE version
Major version
1.0.2
45
1.1
45 (Not a typo, same version)
1.2
46
1.3
47
1.4
48
5.0
49
6
50
7
51
8
52
9
53
10
54
11
55
12
56
13
57
14
58
15
59
16
60
These are the assigned major numbers. The error regarding the unsupported major.minor version is because during compile time you are using a higher JDK and a lower JDK during runtime.
Thus, the 'major.minor version 52.0' error is possibly because the jar was compiled in JDK 1.8, but you are trying to run it using a JDK 1.7 environment. The reported number is the required number, not the number you are using. To solve this, it's always better to have the JDK and JRE pointed to the same version.
In IntelliJ IDEA,
Go to Maven Settings → Maven → Importing. Set the JDK for importer to 1.8.
Go to Maven Settings → Maven → Runner. Set the JRE to 1.8.
Go to menu File* → Project Structure → SDKs. Make sure the JDK home path is set to 1.8.
Restart IntelliJ IDEA.
Another approach which might help is by instructing IntelliJ IDEA which JDK version to start up with.
Go to: /Applications/IntelliJ\ IDEA\ 15\ CE.app/Contents/Info.plist
and replace the JVM version with:
<key>JVMVersion</key>
<string>1.8*</string>
The smart way to fix that problem is to compile using the latest SDK and use the cross compilation options when compiling. To use the options completely correctly requires the rt.jar of a JRE (not JDK) of the target version.
Given the nature of that applet, it looks like it could be compiled for use with Java 1.1 meaning you'd use javac -target 1.1.
You will need to change your compiler compliance level back to 1.7 in your IDE.
This can be done in the preferences settings of your IDE. For example, in Eclipse go to menu Windows → Preferences, select Java, and expand it. Then select Compiler and change the compliance level to 1.7. I am sure this will work from there.
You must run and compile your application with the same version of Java.
If you're using Eclipse you should do 2 things:
In Eclipse, click on "Window > Preferences", and in the window that appears, on the left side, under "Java", click on "Installed JREs", click on "Add..." and navigate to the folder that contains the JDK.
Right-click on your project and click on "Properties", in the window that appears, on the left side, click on "Java Compiler" and uncheck "Use compliance from execution environment on the Java Build Path", this allows you to choose in the the list "Compiler compilance level" the same version that you set in the previous step.
You need to upgrade your Java version to Java 8.
Download latest Java archive
Download latest Java SE Development Kit 8 release from its official download page or use following commands to download from the shell.
For 64 bit
# cd /opt/
# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u51-b16/jdk-8u51-linux-x64.tar.gz"
# tar xzf jdk-8u51-linux-x64.tar.gz
For 32 bit
# cd /opt/
# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u51-b16/jdk-8u51-linux-i586.tar.gz"
# tar xzf jdk-8u51-linux-i586.tar.gz
Note: If the above wget command doesn’t not work for you, watch this example video to download the Java source archive using the terminal.
Install Java with alternatives
After extracting the archive file, use the alternatives command to install it. The alternatives command is available in the chkconfig package.
# cd /opt/jdk1.8.0_51/
# alternatives --install /usr/bin/java java /opt/jdk1.8.0_51/bin/java 2
# alternatives --config java
At this point Java 8 has been successfully installed on your system. We also recommend to setup javac and jar commands path using alternatives:
# alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_51/bin/jar 2
# alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_51/bin/javac 2
# alternatives --set jar /opt/jdk1.8.0_51/bin/jar
# alternatives --set javac /opt/jdk1.8.0_51/bin/javac
Check installed Java version
Check the installed version of Java using the following command.
root#tecadmin ~# java -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
Configuring Environment Variables
Most of Java-based applications use environment variables to work. Set the Java environment variables using the following commands:
Setup JAVA_HOME Variable
# export JAVA_HOME=/opt/jdk1.8.0_51
Setup JRE_HOME Variable
# export JRE_HOME=$JAVA_HOME/jre
Setup PATH Variable
# export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
Note that the change to the PATH variable put the new Java bin folders first so that they override any existing java/bins in the path. It is a bit sloppy to leave two java/bin folders in your path so you should be advised to clean those up as a separate task.
Also, put all above environment variables in the /etc/environment file for auto loading on system boot.
I had the same problem... a JDK and plug-in version conflict.
I compiled using 1.8 ... the latest one, and that message started to appear.
So I've searched for the JRE 7 (http://www.oracle.com/technetwork/java/javase/downloads/server-jre7-downloads-1931105.html)... and installed it... again...
Now 1.8 and 1.7 in the same computer.
Using NetBeans, and compiling, and targeting to version 1.7, fixed my problem.
If you have a problem in Android Studio and you have installed Android N, change the Android rendering version with an older one and the problem will disappear.
If you're using the NetBeans IDE, right click on the project and choose Properties and go to sources, and you can change the Source/Binary Format to a lower JDK version.
Unsupported major.minor version 52.0 comes when you are trying to run a class compiled using Java 1.8 compiler into a lower JRE version e.g. JRE 1.7 or JRE 1.6. Simplest way to fix this error is install the latest Java release i.e. Java 8 and run your program.
Read more: http://javarevisited.blogspot.com/2015/05/fixing-unsupported-majorminor-version.html#ixzz4AVD4Evgv
It happens when you compile your projects on higher version of java(say jdk 1.8) and then run it on a lower version (say jdk 1.7).
If you have JRE-1.7 library in your project path then ,
1.Right click on project
2.Go to Properties
3.Select Project Facets
4.Find Java in rows and then choose version (say 1.7) if using JRE-1.7
5.Click Apply and run your project.
I solved my problem by removing old versions of JRE and installing JRE 8.
I could solve the same problem using the below solution.
In my project, I added a JAR file which were created in Java 8. And my project was referring to JRE 7. When I changed project JRE to 8, my problem was solved.
Steps:
In Eclipse, right click on the project name in project explorer → Build path → Libraries → click on JRE version → click Edit → Installed JRE → Add → Standerd VM → select JRE home click-path (path should be localePath\java\jdk1.8.0_25\jre) → provide name → Save → select same JRE for project → Finish → OK. Refresh/build project once → try to run your Java file. It should work.
I had Java 1.7 & 1.8 installed (with SBT 2.4 that requires Java 1.8).
Even though my project was linked to Java 1.8, I had to change the JAVA_HOME environment variable to point 1.8.
Finally, problem solved.
If you are using Eclipse, make sure your menu Project → Properties → Java build path → libraries → JRE system library matches your project requirements (as shown in the image).
All you need to do to solve the problem is... to make sure your version of Java is the same for both compiling and running. No matter what tools or IDEs you are using.
If you are using Linux and you have different versions of Java installed, use the following command:
sudo update-alternatives --config java
This will give a quick way of switching between the Java versions installed on the system. By choosing Java 8 I will solve your problem.
This occurred to me when I installed a fresh Java 1.8, but left the old command line interpreter open.
It had an old path and kept on executing the application with Java 1.7 whereas project was already built with Java 1.8.
If your JDK version is right. Another reason that may cause this error is that your Android Studio is in a low version, but your Gradle version is too high. Upgrade your IDE to a newer version may help this.
Upgrade your Andorra version to JDK 1.8.
This is a version mismatch that your compiler is looking for Java version 8 and you have Java version 7.
You can run an app build in version 7 in version 8, but you can't do vice versa because when it comes to higher levels, versions are embedded with more features, enhancements rather than previous versions.
Download JDK version from this link
And set your JDK path for this
You need to use JDK 1.7.0 rather than JDK 1.8.0.
To make sure it, you need to delete JDK 1.8.0 on your computer.
If you use Mac, you need to delete:
/Library/Java/JavaVirtualMachines/jdk.jdk
/Library/PreferencePanes/JavaControlPanel.prefPane
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin
Then, you need to reinstall JDK 1.7.0, and you will succeed to generate the .jar file.
You may want to check your Run Configurations setting if you're using Eclipse v4.4 (Luna) and have already completed all steps mentioned above.
There could be several possibilities that cause this error. The root cause is a mismatch of the project require compilation in JDK1.8/JRE8 while the environment compiler is JDK1.7/JRE7.
You can check my blog post to go through all your settings are correct.
None of these answers helped me, but I found a solution.
I had a webproject used in Wildfly 8.2, built with Maven, source and target was set to 1.8 on maven-compiler-plugin, as well as all Eclipse and Maven settings were set to Java 1.8.
The problem was that Wildfly 8.2 cannot handle Java 1.8, so I had to set everything to 1.7 and it worked.
Just want to add this. I had this problem today. Adjusted the settings in my project, rebuilt, and same problem. I had (incorrectly) assumed that changing the settings in my project (Eclipse) would cause the projects on which my project depends to be recompiled also.
Adjusting the settings to all of the projects up the dependency tree solved the problem.
Just go to http://java.com/en/download/ and update your version of JRE
If you are using IntelliJ IDEA, go to Project Structure (Ctrl + Alt + Shift + S), and you can change your project's JDK.
I ran into this issue in Eclipse on Mac OS X v10.9 (Mavericks). I tried many answers on Stack Overflow ... finally, after a full day I *installed a fresh version of the Android SDK (and updated Eclipse, menu Project → Properties → Android to use the new path)*.
I had to get SDK updates, but only pulling down those updates I thought were necessary, avoiding APIs I were not working with (like Wear and TV) .. and that did the trick. Apparently, it seems I had corrupted my SDK somewhere along the way.
BTW .. I did see the error re-surface with one project in my workspace, but it seemed related to an import of appcompat-7, which I was not using. After rm-ing that project, so far haven't seen the issue resurface.
Related
This question already has answers here:
How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version
(51 answers)
Closed 6 years ago.
Pictures:
Command Prompt showing versions
Picture of error
Hello.java
import java.applet.Applet;
import java.awt.*;
public class Hello extends Applet {
// Java applet to draw "Hello World"
public void paint (Graphics page) {
page.drawString ("Hello World!", 50, 50);
}
}
Hello.html
<HTML>
<HEAD>
<TITLE>HelloWorld Applet</TITLE>
</HEAD>
<BODY>
<APPLET CODE="Hello.class" WIDTH=300 HEIGHT=150>
</APPLET>
</BODY>
</HTML>
Error
Hello : Unsupported major.minor version 52.0
What may the problem be?
The issue is because of Java version mismatch. Referring to the JVM specification the following are the major versions of classfiles for use with different versions of Java. (As of now, all versions support all previous versions.)
Java SE version
Major version
1.0.2
45
1.1
45 (Not a typo, same version)
1.2
46
1.3
47
1.4
48
5.0
49
6
50
7
51
8
52
9
53
10
54
11
55
12
56
13
57
14
58
15
59
16
60
These are the assigned major numbers. The error regarding the unsupported major.minor version is because during compile time you are using a higher JDK and a lower JDK during runtime.
Thus, the 'major.minor version 52.0' error is possibly because the jar was compiled in JDK 1.8, but you are trying to run it using a JDK 1.7 environment. The reported number is the required number, not the number you are using. To solve this, it's always better to have the JDK and JRE pointed to the same version.
In IntelliJ IDEA,
Go to Maven Settings → Maven → Importing. Set the JDK for importer to 1.8.
Go to Maven Settings → Maven → Runner. Set the JRE to 1.8.
Go to menu File* → Project Structure → SDKs. Make sure the JDK home path is set to 1.8.
Restart IntelliJ IDEA.
Another approach which might help is by instructing IntelliJ IDEA which JDK version to start up with.
Go to: /Applications/IntelliJ\ IDEA\ 15\ CE.app/Contents/Info.plist
and replace the JVM version with:
<key>JVMVersion</key>
<string>1.8*</string>
The smart way to fix that problem is to compile using the latest SDK and use the cross compilation options when compiling. To use the options completely correctly requires the rt.jar of a JRE (not JDK) of the target version.
Given the nature of that applet, it looks like it could be compiled for use with Java 1.1 meaning you'd use javac -target 1.1.
You will need to change your compiler compliance level back to 1.7 in your IDE.
This can be done in the preferences settings of your IDE. For example, in Eclipse go to menu Windows → Preferences, select Java, and expand it. Then select Compiler and change the compliance level to 1.7. I am sure this will work from there.
You must run and compile your application with the same version of Java.
If you're using Eclipse you should do 2 things:
In Eclipse, click on "Window > Preferences", and in the window that appears, on the left side, under "Java", click on "Installed JREs", click on "Add..." and navigate to the folder that contains the JDK.
Right-click on your project and click on "Properties", in the window that appears, on the left side, click on "Java Compiler" and uncheck "Use compliance from execution environment on the Java Build Path", this allows you to choose in the the list "Compiler compilance level" the same version that you set in the previous step.
You need to upgrade your Java version to Java 8.
Download latest Java archive
Download latest Java SE Development Kit 8 release from its official download page or use following commands to download from the shell.
For 64 bit
# cd /opt/
# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u51-b16/jdk-8u51-linux-x64.tar.gz"
# tar xzf jdk-8u51-linux-x64.tar.gz
For 32 bit
# cd /opt/
# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u51-b16/jdk-8u51-linux-i586.tar.gz"
# tar xzf jdk-8u51-linux-i586.tar.gz
Note: If the above wget command doesn’t not work for you, watch this example video to download the Java source archive using the terminal.
Install Java with alternatives
After extracting the archive file, use the alternatives command to install it. The alternatives command is available in the chkconfig package.
# cd /opt/jdk1.8.0_51/
# alternatives --install /usr/bin/java java /opt/jdk1.8.0_51/bin/java 2
# alternatives --config java
At this point Java 8 has been successfully installed on your system. We also recommend to setup javac and jar commands path using alternatives:
# alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_51/bin/jar 2
# alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_51/bin/javac 2
# alternatives --set jar /opt/jdk1.8.0_51/bin/jar
# alternatives --set javac /opt/jdk1.8.0_51/bin/javac
Check installed Java version
Check the installed version of Java using the following command.
root#tecadmin ~# java -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
Configuring Environment Variables
Most of Java-based applications use environment variables to work. Set the Java environment variables using the following commands:
Setup JAVA_HOME Variable
# export JAVA_HOME=/opt/jdk1.8.0_51
Setup JRE_HOME Variable
# export JRE_HOME=$JAVA_HOME/jre
Setup PATH Variable
# export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
Note that the change to the PATH variable put the new Java bin folders first so that they override any existing java/bins in the path. It is a bit sloppy to leave two java/bin folders in your path so you should be advised to clean those up as a separate task.
Also, put all above environment variables in the /etc/environment file for auto loading on system boot.
I had the same problem... a JDK and plug-in version conflict.
I compiled using 1.8 ... the latest one, and that message started to appear.
So I've searched for the JRE 7 (http://www.oracle.com/technetwork/java/javase/downloads/server-jre7-downloads-1931105.html)... and installed it... again...
Now 1.8 and 1.7 in the same computer.
Using NetBeans, and compiling, and targeting to version 1.7, fixed my problem.
If you have a problem in Android Studio and you have installed Android N, change the Android rendering version with an older one and the problem will disappear.
If you're using the NetBeans IDE, right click on the project and choose Properties and go to sources, and you can change the Source/Binary Format to a lower JDK version.
Unsupported major.minor version 52.0 comes when you are trying to run a class compiled using Java 1.8 compiler into a lower JRE version e.g. JRE 1.7 or JRE 1.6. Simplest way to fix this error is install the latest Java release i.e. Java 8 and run your program.
Read more: http://javarevisited.blogspot.com/2015/05/fixing-unsupported-majorminor-version.html#ixzz4AVD4Evgv
It happens when you compile your projects on higher version of java(say jdk 1.8) and then run it on a lower version (say jdk 1.7).
If you have JRE-1.7 library in your project path then ,
1.Right click on project
2.Go to Properties
3.Select Project Facets
4.Find Java in rows and then choose version (say 1.7) if using JRE-1.7
5.Click Apply and run your project.
I solved my problem by removing old versions of JRE and installing JRE 8.
I could solve the same problem using the below solution.
In my project, I added a JAR file which were created in Java 8. And my project was referring to JRE 7. When I changed project JRE to 8, my problem was solved.
Steps:
In Eclipse, right click on the project name in project explorer → Build path → Libraries → click on JRE version → click Edit → Installed JRE → Add → Standerd VM → select JRE home click-path (path should be localePath\java\jdk1.8.0_25\jre) → provide name → Save → select same JRE for project → Finish → OK. Refresh/build project once → try to run your Java file. It should work.
I had Java 1.7 & 1.8 installed (with SBT 2.4 that requires Java 1.8).
Even though my project was linked to Java 1.8, I had to change the JAVA_HOME environment variable to point 1.8.
Finally, problem solved.
If you are using Eclipse, make sure your menu Project → Properties → Java build path → libraries → JRE system library matches your project requirements (as shown in the image).
All you need to do to solve the problem is... to make sure your version of Java is the same for both compiling and running. No matter what tools or IDEs you are using.
If you are using Linux and you have different versions of Java installed, use the following command:
sudo update-alternatives --config java
This will give a quick way of switching between the Java versions installed on the system. By choosing Java 8 I will solve your problem.
This occurred to me when I installed a fresh Java 1.8, but left the old command line interpreter open.
It had an old path and kept on executing the application with Java 1.7 whereas project was already built with Java 1.8.
If your JDK version is right. Another reason that may cause this error is that your Android Studio is in a low version, but your Gradle version is too high. Upgrade your IDE to a newer version may help this.
Upgrade your Andorra version to JDK 1.8.
This is a version mismatch that your compiler is looking for Java version 8 and you have Java version 7.
You can run an app build in version 7 in version 8, but you can't do vice versa because when it comes to higher levels, versions are embedded with more features, enhancements rather than previous versions.
Download JDK version from this link
And set your JDK path for this
You need to use JDK 1.7.0 rather than JDK 1.8.0.
To make sure it, you need to delete JDK 1.8.0 on your computer.
If you use Mac, you need to delete:
/Library/Java/JavaVirtualMachines/jdk.jdk
/Library/PreferencePanes/JavaControlPanel.prefPane
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin
Then, you need to reinstall JDK 1.7.0, and you will succeed to generate the .jar file.
You may want to check your Run Configurations setting if you're using Eclipse v4.4 (Luna) and have already completed all steps mentioned above.
There could be several possibilities that cause this error. The root cause is a mismatch of the project require compilation in JDK1.8/JRE8 while the environment compiler is JDK1.7/JRE7.
You can check my blog post to go through all your settings are correct.
None of these answers helped me, but I found a solution.
I had a webproject used in Wildfly 8.2, built with Maven, source and target was set to 1.8 on maven-compiler-plugin, as well as all Eclipse and Maven settings were set to Java 1.8.
The problem was that Wildfly 8.2 cannot handle Java 1.8, so I had to set everything to 1.7 and it worked.
Just want to add this. I had this problem today. Adjusted the settings in my project, rebuilt, and same problem. I had (incorrectly) assumed that changing the settings in my project (Eclipse) would cause the projects on which my project depends to be recompiled also.
Adjusting the settings to all of the projects up the dependency tree solved the problem.
Just go to http://java.com/en/download/ and update your version of JRE
If you are using IntelliJ IDEA, go to Project Structure (Ctrl + Alt + Shift + S), and you can change your project's JDK.
I ran into this issue in Eclipse on Mac OS X v10.9 (Mavericks). I tried many answers on Stack Overflow ... finally, after a full day I *installed a fresh version of the Android SDK (and updated Eclipse, menu Project → Properties → Android to use the new path)*.
I had to get SDK updates, but only pulling down those updates I thought were necessary, avoiding APIs I were not working with (like Wear and TV) .. and that did the trick. Apparently, it seems I had corrupted my SDK somewhere along the way.
BTW .. I did see the error re-surface with one project in my workspace, but it seemed related to an import of appcompat-7, which I was not using. After rm-ing that project, so far haven't seen the issue resurface.
This question already has answers here:
How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version
(51 answers)
Closed 6 years ago.
Pictures:
Command Prompt showing versions
Picture of error
Hello.java
import java.applet.Applet;
import java.awt.*;
public class Hello extends Applet {
// Java applet to draw "Hello World"
public void paint (Graphics page) {
page.drawString ("Hello World!", 50, 50);
}
}
Hello.html
<HTML>
<HEAD>
<TITLE>HelloWorld Applet</TITLE>
</HEAD>
<BODY>
<APPLET CODE="Hello.class" WIDTH=300 HEIGHT=150>
</APPLET>
</BODY>
</HTML>
Error
Hello : Unsupported major.minor version 52.0
What may the problem be?
The issue is because of Java version mismatch. Referring to the JVM specification the following are the major versions of classfiles for use with different versions of Java. (As of now, all versions support all previous versions.)
Java SE version
Major version
1.0.2
45
1.1
45 (Not a typo, same version)
1.2
46
1.3
47
1.4
48
5.0
49
6
50
7
51
8
52
9
53
10
54
11
55
12
56
13
57
14
58
15
59
16
60
These are the assigned major numbers. The error regarding the unsupported major.minor version is because during compile time you are using a higher JDK and a lower JDK during runtime.
Thus, the 'major.minor version 52.0' error is possibly because the jar was compiled in JDK 1.8, but you are trying to run it using a JDK 1.7 environment. The reported number is the required number, not the number you are using. To solve this, it's always better to have the JDK and JRE pointed to the same version.
In IntelliJ IDEA,
Go to Maven Settings → Maven → Importing. Set the JDK for importer to 1.8.
Go to Maven Settings → Maven → Runner. Set the JRE to 1.8.
Go to menu File* → Project Structure → SDKs. Make sure the JDK home path is set to 1.8.
Restart IntelliJ IDEA.
Another approach which might help is by instructing IntelliJ IDEA which JDK version to start up with.
Go to: /Applications/IntelliJ\ IDEA\ 15\ CE.app/Contents/Info.plist
and replace the JVM version with:
<key>JVMVersion</key>
<string>1.8*</string>
The smart way to fix that problem is to compile using the latest SDK and use the cross compilation options when compiling. To use the options completely correctly requires the rt.jar of a JRE (not JDK) of the target version.
Given the nature of that applet, it looks like it could be compiled for use with Java 1.1 meaning you'd use javac -target 1.1.
You will need to change your compiler compliance level back to 1.7 in your IDE.
This can be done in the preferences settings of your IDE. For example, in Eclipse go to menu Windows → Preferences, select Java, and expand it. Then select Compiler and change the compliance level to 1.7. I am sure this will work from there.
You must run and compile your application with the same version of Java.
If you're using Eclipse you should do 2 things:
In Eclipse, click on "Window > Preferences", and in the window that appears, on the left side, under "Java", click on "Installed JREs", click on "Add..." and navigate to the folder that contains the JDK.
Right-click on your project and click on "Properties", in the window that appears, on the left side, click on "Java Compiler" and uncheck "Use compliance from execution environment on the Java Build Path", this allows you to choose in the the list "Compiler compilance level" the same version that you set in the previous step.
You need to upgrade your Java version to Java 8.
Download latest Java archive
Download latest Java SE Development Kit 8 release from its official download page or use following commands to download from the shell.
For 64 bit
# cd /opt/
# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u51-b16/jdk-8u51-linux-x64.tar.gz"
# tar xzf jdk-8u51-linux-x64.tar.gz
For 32 bit
# cd /opt/
# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u51-b16/jdk-8u51-linux-i586.tar.gz"
# tar xzf jdk-8u51-linux-i586.tar.gz
Note: If the above wget command doesn’t not work for you, watch this example video to download the Java source archive using the terminal.
Install Java with alternatives
After extracting the archive file, use the alternatives command to install it. The alternatives command is available in the chkconfig package.
# cd /opt/jdk1.8.0_51/
# alternatives --install /usr/bin/java java /opt/jdk1.8.0_51/bin/java 2
# alternatives --config java
At this point Java 8 has been successfully installed on your system. We also recommend to setup javac and jar commands path using alternatives:
# alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_51/bin/jar 2
# alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_51/bin/javac 2
# alternatives --set jar /opt/jdk1.8.0_51/bin/jar
# alternatives --set javac /opt/jdk1.8.0_51/bin/javac
Check installed Java version
Check the installed version of Java using the following command.
root#tecadmin ~# java -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
Configuring Environment Variables
Most of Java-based applications use environment variables to work. Set the Java environment variables using the following commands:
Setup JAVA_HOME Variable
# export JAVA_HOME=/opt/jdk1.8.0_51
Setup JRE_HOME Variable
# export JRE_HOME=$JAVA_HOME/jre
Setup PATH Variable
# export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
Note that the change to the PATH variable put the new Java bin folders first so that they override any existing java/bins in the path. It is a bit sloppy to leave two java/bin folders in your path so you should be advised to clean those up as a separate task.
Also, put all above environment variables in the /etc/environment file for auto loading on system boot.
I had the same problem... a JDK and plug-in version conflict.
I compiled using 1.8 ... the latest one, and that message started to appear.
So I've searched for the JRE 7 (http://www.oracle.com/technetwork/java/javase/downloads/server-jre7-downloads-1931105.html)... and installed it... again...
Now 1.8 and 1.7 in the same computer.
Using NetBeans, and compiling, and targeting to version 1.7, fixed my problem.
If you have a problem in Android Studio and you have installed Android N, change the Android rendering version with an older one and the problem will disappear.
If you're using the NetBeans IDE, right click on the project and choose Properties and go to sources, and you can change the Source/Binary Format to a lower JDK version.
Unsupported major.minor version 52.0 comes when you are trying to run a class compiled using Java 1.8 compiler into a lower JRE version e.g. JRE 1.7 or JRE 1.6. Simplest way to fix this error is install the latest Java release i.e. Java 8 and run your program.
Read more: http://javarevisited.blogspot.com/2015/05/fixing-unsupported-majorminor-version.html#ixzz4AVD4Evgv
It happens when you compile your projects on higher version of java(say jdk 1.8) and then run it on a lower version (say jdk 1.7).
If you have JRE-1.7 library in your project path then ,
1.Right click on project
2.Go to Properties
3.Select Project Facets
4.Find Java in rows and then choose version (say 1.7) if using JRE-1.7
5.Click Apply and run your project.
I solved my problem by removing old versions of JRE and installing JRE 8.
I could solve the same problem using the below solution.
In my project, I added a JAR file which were created in Java 8. And my project was referring to JRE 7. When I changed project JRE to 8, my problem was solved.
Steps:
In Eclipse, right click on the project name in project explorer → Build path → Libraries → click on JRE version → click Edit → Installed JRE → Add → Standerd VM → select JRE home click-path (path should be localePath\java\jdk1.8.0_25\jre) → provide name → Save → select same JRE for project → Finish → OK. Refresh/build project once → try to run your Java file. It should work.
I had Java 1.7 & 1.8 installed (with SBT 2.4 that requires Java 1.8).
Even though my project was linked to Java 1.8, I had to change the JAVA_HOME environment variable to point 1.8.
Finally, problem solved.
If you are using Eclipse, make sure your menu Project → Properties → Java build path → libraries → JRE system library matches your project requirements (as shown in the image).
All you need to do to solve the problem is... to make sure your version of Java is the same for both compiling and running. No matter what tools or IDEs you are using.
If you are using Linux and you have different versions of Java installed, use the following command:
sudo update-alternatives --config java
This will give a quick way of switching between the Java versions installed on the system. By choosing Java 8 I will solve your problem.
This occurred to me when I installed a fresh Java 1.8, but left the old command line interpreter open.
It had an old path and kept on executing the application with Java 1.7 whereas project was already built with Java 1.8.
If your JDK version is right. Another reason that may cause this error is that your Android Studio is in a low version, but your Gradle version is too high. Upgrade your IDE to a newer version may help this.
Upgrade your Andorra version to JDK 1.8.
This is a version mismatch that your compiler is looking for Java version 8 and you have Java version 7.
You can run an app build in version 7 in version 8, but you can't do vice versa because when it comes to higher levels, versions are embedded with more features, enhancements rather than previous versions.
Download JDK version from this link
And set your JDK path for this
You need to use JDK 1.7.0 rather than JDK 1.8.0.
To make sure it, you need to delete JDK 1.8.0 on your computer.
If you use Mac, you need to delete:
/Library/Java/JavaVirtualMachines/jdk.jdk
/Library/PreferencePanes/JavaControlPanel.prefPane
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin
Then, you need to reinstall JDK 1.7.0, and you will succeed to generate the .jar file.
You may want to check your Run Configurations setting if you're using Eclipse v4.4 (Luna) and have already completed all steps mentioned above.
There could be several possibilities that cause this error. The root cause is a mismatch of the project require compilation in JDK1.8/JRE8 while the environment compiler is JDK1.7/JRE7.
You can check my blog post to go through all your settings are correct.
None of these answers helped me, but I found a solution.
I had a webproject used in Wildfly 8.2, built with Maven, source and target was set to 1.8 on maven-compiler-plugin, as well as all Eclipse and Maven settings were set to Java 1.8.
The problem was that Wildfly 8.2 cannot handle Java 1.8, so I had to set everything to 1.7 and it worked.
Just want to add this. I had this problem today. Adjusted the settings in my project, rebuilt, and same problem. I had (incorrectly) assumed that changing the settings in my project (Eclipse) would cause the projects on which my project depends to be recompiled also.
Adjusting the settings to all of the projects up the dependency tree solved the problem.
Just go to http://java.com/en/download/ and update your version of JRE
If you are using IntelliJ IDEA, go to Project Structure (Ctrl + Alt + Shift + S), and you can change your project's JDK.
I ran into this issue in Eclipse on Mac OS X v10.9 (Mavericks). I tried many answers on Stack Overflow ... finally, after a full day I *installed a fresh version of the Android SDK (and updated Eclipse, menu Project → Properties → Android to use the new path)*.
I had to get SDK updates, but only pulling down those updates I thought were necessary, avoiding APIs I were not working with (like Wear and TV) .. and that did the trick. Apparently, it seems I had corrupted my SDK somewhere along the way.
BTW .. I did see the error re-surface with one project in my workspace, but it seemed related to an import of appcompat-7, which I was not using. After rm-ing that project, so far haven't seen the issue resurface.
I am trying to use Notepad++ as my all-in-one tool edit, run, compile, etc.
I have JRE installed, and I have setup my path variable to the .../bin directory.
When I run my "Hello world" in Notepad++, I get this message:
java.lang.UnsupportedClassVersionError: test_hello_world :
Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
.........................................
I think the problem here is about versions; some versions of Java may be old or too new.
How do I fix it?
Should I install the JDK, and setup my path variable to the JDK instead of JRE?
What is the difference between the PATH variable in JRE or JDK?
The version number shown describes the version of the JRE the class file is compatible with.
The reported major numbers are:
Java SE 19 = 63,
Java SE 18 = 62,
Java SE 17 = 61,
Java SE 16 = 60,
Java SE 15 = 59,
Java SE 14 = 58,
Java SE 13 = 57,
Java SE 12 = 56,
Java SE 11 = 55,
Java SE 10 = 54,
Java SE 9 = 53,
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
(Source: Wikipedia)
To fix the actual problem you should try to either run the Java code with a newer version of Java JRE or specify the target parameter to the Java compiler to instruct the compiler to create code compatible with earlier Java versions.
For example, in order to generate class files compatible with Java 1.4, use the following command line:
javac -target 1.4 HelloWorld.java
With newer versions of the Java compiler you are likely to get a warning about the bootstrap class path not being set. More information about this error is available in a blog post New javac warning for setting an older source without bootclasspath.
java.lang.UnsupportedClassVersionError happens because of a higher JDK during compile time and lower JDK during runtime.
In Eclipse, I just went to menu command Window -> Preferences -> Java -> Compiler and then set "Compiler compliance level" to 1.6.
Don't worry, I got it solved.
It is actually simple - you need to install BOTH JRE / JDK with the same version.
JRE 6 -> JDK 6
JRE 7 -> JDK 7
And so on.
This error means you're trying to load a Java "class" file that was compiled with a newer version of Java than you have installed.
For example, your .class file could have been compiled for JDK 7, and you're trying to run it with JDK 6.
So the solution is to either:
Upgrade your Java runtime or
Recompile the class if you have the source, using your local Java compiler (if you have one).
javac FileName.java
For developers, this can happen if another developer checks in a .class file, and they've got a newer version of java than you have!
You are trying to run your program with a Java version that does not support the version in which the code was compiled. So basically you must have compiled your code with a higher version and trying to run it using a lower version.
As you are getting
Unsupported major.minor version 51.0
and version 51.0 corresponds to J2SE 7 you have most probably compiled your code in Java 7 and trying to run it using a lower version. Check what java -version displays. It should be the Java 7 version. If not make appropriate changes in the PATH/JAVA_HOME. Or you can compile with the same version you are trying to run the code. If the configurations are confusing you can always give absolute path /home/user/jdk1.7.0_11/bin/javac and /home/user/jdk1.7.0_11/bin/java.
I had a similar situation on Mac, and the following process worked for me:
In the terminal, type
vi ~/.profile
Then add this line in the file, and save
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk<version>.jdk/Contents/Home
where version is the one on your computer, such as 1.7.0_25.
Exit the editor, then type the following command make it become effective
source ~/.profile
Then type java -version to check the result
java -version
What is .profile file?
.profile file is a hidden file. It is an optional file which tells the system which commands to run when the user whose profile file it is logs in. For example, if my username is bruno and there is a .profile file in /Users/bruno/, all of its contents will be executed during the log-in procedure.
Source: http://computers.tutsplus.com/tutorials/speed-up-your-terminal-workflow-with-command-aliases-and-profile--mac-30515
In Eclipse's menu Window -> Preferences -> Java -> Compiler check also "Configure Project Specific Settings".
If you stil have the error with same Java version: try to delete build folder of your project manually. Then restart Eclipse.
You can have some JAR library compiled in Java 7, and you have only Java 6 as Java Runtime. It could happen with some new libraries.
The most common issue is misconfiguration of your JAVA_HOME variable which should point to the right Java Development Kit library, if you've multiple installed.
To find where SDK Java folder is located, run the following commands:
jrunscript -e 'java.lang.System.out.println(java.lang.System.getProperty("java.home"));'
Debian/Ubuntu
To check which java (openjdk) you've installed, check via:
dpkg -l "openjdk*" | grep ^i
or:
update-java-alternatives -l
To change it, use:
update-alternatives --config java
Prefix with sudo if required.
to select the alternative java version.
Or check which are available for install:
apt-cache search ^openjdk
Prefix with sudo if required.
Then you can install, for example:
apt-get install openjdk-7-jre
Prefix with sudo if required.
Fedora, Oracle Linux, Red Hat
Install/upgrade appropriate package via:
yum install java-1.7.0-openjdk java-1.7.0-openjdk-devel
The java-1.7.0-openjdk package contains just the Java Runtime Environment. If you want to develop Java programs then install the java-1.7.0-openjdk-devel package.
BSD
There is an OpenJDK 7 package in the FreeBSD Ports collection called openjdk7 which probably needs to be reconfigured.
See: OpenJDK wiki page.
Windows
Just install appropriate Java SE Development Kit library from the Oracle site or install
Jenkins
If you're experiencing this issue with Jenkins, see:
JENKINS-30561 - Unable to launch agent using SSH
However selecting the right version of Java (newer) with update-alternatives should work.
I got the same problem with a project written in 1.7 and tried to execute in 1.6.
My solution in Eclipse:
Right click on your Project Properties -> Java Build Path -> Libraries
Select your JRE System Library and click Edit on the right, and choose the target JRE.
Now go to Java Compiler on the left, and change the Compiler compliance level to your target.
That worked for me.
I have faced the same problem when I was working with an Ant script to build my application.
I use Eclipse for my application development, and I changed the compiler version in build properties of the project. But that didn't work for me. Then I found out that I can provide the compiler version in the Ant script.
I modified the Ant script at the section where it compile Java files.
<target name="build-java" depends="prepare-build">
<echo message="Compiling java files"/>
<javac ....
target="1.5"...
</javac>
</target>
This worked for me to resolve the unsupported major minor issue.
When I installed JDK 1.7, the problem got solved.
Based on this...
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
In Eclipse, right click on project in package explorer:
Build Path -> Configure Build Path
Under:
Java Build Path -> Libraries -> Add Library -> JRE System Library -> Installed JREs -> Search.
Add the required JRE by selecting the library in the list available after the search is complete.
As answered elsewhere by several people, the Java program is being run on an older version of Java than the one it was compiled it for. It needs to be "crosscompiled" for backward compatibility. To put it another way, there is a mismatch between source and target Java versions.
Changing options in Eclipse menus don't answer the original poster, who said he/she is not using Eclipse. On OpenJDK javac version 1.7, you can crosscompile for 1.6 if you use parameters -source and -target, plus provide the rt.jar -file of the target version (that is, the older one) at compile time. If you actually install the 1.6 JRE, you can point to its installation (for example, /usr/lib/jvm/java-6-openjdk-i386/jre/lib/rt.jar on Ubuntu, /usr/jdk/jdk1.6.0_60/jre/lib/rt.jar on SunOS apparently. Sorry, I don't know where it is on a Windows system). Like so:
javac -source 1.6 -target 1.6 -bootclasspath /usr/lib/jvm/java-6-openjdk-i386/jre/lib/rt.jar HelloWorld.java
It looks like you can just download rt.jar from the Internet, and point to it. This is not too elegant though:
javac -source 1.6 -target 1.6 -bootclasspath ./rt.jar HelloWorld.java
If you use Maven, set your Java compile level. Open a command line and write java -version for your compile level:
If you use IntelliJ IDEA, select project → File → Settings → Build Execution Deployment → Compiler → Java Compiler. Then change byte code as 1.7 like this image:
If you're facing this issue while using Maven, you can compile your code using the plug-in Maven Compiler.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
.....
UPDATE: set source and target to 1.8, if you are using JDK 8.
I had the same error message when running Ant from Eclipse, but the other solutions mentioned here didn't solve my problem. The funny thing was that running Ant from the Windows command line was running fine, so it had to be a configuration issue within Eclipse.
It turned out that under Eclipse you can specify the environment that Ant should be running with and this was set as a JRE instead of a JDK.
Go to: Run -> External Tools -> External Tools Configurations ...
Select the Ant build.xml for your project (if you have multiple projects)
Activate the Tab 'JRE'
Here was selected 'Separate JRE: jre6'. When I changed this to a JDK from the 1.6 or 1.7 series, the error was gone.
You have used a higher version of the JDK to compile and trying to run from a lower version of JDK/JRE.
To check this, see the version information:
javac -version
java -version
They will be different and javac will have a higher version number.
To get around this, run using java from the JDK version or if you have a newer JRE/JDK that will work as well.
which javac will tell you the location, for example, /usr/bin/javac. Just run directly using /usr/bin/java <program>.
OR you can set the environment variable as a permanent solution.
How do I fix it?
This error means that the JRE that is being used to execute your class code does not recognise the version of Java used. Usually because the version of Java that generated your class file (i.e. compiled it) is newer.
To fix it, you can either
a) Compile your Java sources with the same, or older, version of the Java compiler as will be used to run it. i.e. install the appropriate JDK.
b) Compile your Java sources with the newer version of the Java compiler but in compatibility mode. i.e. use the -target parameter.
c) Run your compiled classes in a JRE that is the same, or newer, version as the JDK used to compile the classes.
You can check the versions you are currently using with
javac -version for the compiler, and java -version for the runtime.
Should I install the JDK, and setup my PATH variable to the JDK
instead of JRE?
For compilation, certainly, install and configure the specific JDK that you want.
For runtime, you can use the one that comes with the JDK or a standalone JRE, but regardless, make sure that you have installed the right versions and that you have configured your PATH such that there are no surprises.
What is the difference between the PATH variable in JRE or JDK?
The PATH environment variable tells the command shell where to look for the command you type. When you type java, the command shell interpreter will look through all the locations specified in the PATH variable, from left to right, to find the appropriate java runtime executable to run. If you have multiple versions of Java installed - i.e. you have the java executable in multiple locations specified in the PATH variable, then the first one encountered when going from left to right will be the one that is executed.
The compiler command is javac and only comes with the JDK. The runtime command is java and comes with the JDK and is in the JRE.
It is likely that you have one version (51.0 = Java 7) of javac installed, and you also have the same version of java installed, but that another previous version of java is appearing earlier in the PATH and so is being invoked instead of the one you expect.
Had this problem when I reverted to Java 6 and tried to run classes previously compiled with Java 7. What worked for me was Preferences > java > compiler --> set compliance level to 1.6 and crucially "configure project settings"..
Today, this error message appeared in our Tomcat 7 on Ubuntu 12.04.2 LTS (Precise Pangolin):
/var/log/tomcat7/localhost.2014-04-08.log:
Apr 8, 2014 9:00:55 AM org.apache.catalina.core.StandardContext filterStart
SEVERE: Exception starting filter struts2
java.lang.UnsupportedClassVersionError: controller/ReqAccept : Unsupported major.minor version 51.0 (unable to load class controller.ReqAccept)
The Struts application is compiled with Java 7.
It turned out, someone uses "service tomcat [stop/start]" to restart Tomcat 7,
$ ps -ef | grep java
tomcat7 31783 1 32 20:13 ? 00:00:03 /usr/lib/jvm/default-java/bin/java...
$ /usr/lib/jvm/default-java/bin/java -version
java version "1.6.0_27"
Which causes the "Unsupported major.minor version 51.0" error.
When we used "/etc/init.d/tomcat7 [stop/start]" to restart Tomcat 7, the problem was solved.
$ ps -ef | grep java
tomcat7 31886 1 80 20:24 ? 00:00:10 /usr/local/java/jdk1.7.0_15/bin/java
$ /usr/local/java/jdk1.7.0_15/bin/java -version
java version "1.7.0_15"
I solved it. I ran:
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386
The error is misleading, Unsupported major.minor version 51.0. This gives the impression that version 51 (Java 7) is not supported. And we should use Java 6.
The error should have been:
The current Java version, 50, is unsupported. Use Java version 7 (51:0 and greater) instead.`
Your Java file is compiled with a different version (higher compiler version) than the version (lower runtime version) you are trying to run it with.
It is basic understanding that classes compiled with lower versions are expected to run in the later higher versions. But the opposite (compiled with higher compiler version and trying to run it with lower runtime version) is quite not possible sometimes.
Hence you are shown this error, when trying to execute your program. Unsupported major.minor version x.x
Q: I have created an application in Java 7, but when my users try to
run it they get an Unsupported major.minor version 51.0 error. What
does this mean and what can I do about it?
A: If you compile an application using javac in Java 7, the resulting classfiles will have the 51.0 version number. Versions of
Java prior to 7 do not recognize this number, so your users will have
to upgrade to Java 7 prior to running your application. If you are not
using any Java 7 APIs you can try to compile your application using
javac -target 1.6 to create a 1.6-compatible classfile. If your
application is deployed using webstart you can specify the minimum
version required. For more information, see the docs on Java Web Start
and JNLP here. This issue will go away once we trigger autoupdate to
Java 7 for end-users currently having Java 6 on their desktops. The
timeline for this is not yet determined, we want to give developers
time to work out any issues between their code and JDK 7 first.
(Source: oracle.com.)
Oh Mac OS X I was able to solve this problem by setting the JAVA_HOME variable:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home
First let's get some basics right...
JRE is a component in NetBeans/Eclipse/standalone that is going to provide you with libraries, JVM, Java plugins & Java web start. Note that it does not provide compliers or debuggers.
JDK is the superset of JRE along with compliers and debuggers.
So when you have your default library as a JRE instead of JDK, you are going to have a nice time importing stuff, but it won't compile.
Instead, set your path to JDK (I use NetBeans, and I set them using netbeans.conf in netbeans/etc/netbeans.conf and change the path).
In my case the problem was in the server runtime configuration:
Check the JRE is the version you need:
The project was in version 1.7 and the server JRE was set as 1.6, after changing to the proper java version it's launched fine.
I had the problem whereby I was having to run a Maven compilation on my project from the command line in order to run my unit tests; if I made a change to the test class and let Eclipse automatically recompile it, then I got the "Unsupported major.minor version 51.0" error.
I do have both JDK6 and JDK7 installed, but all my JRE settings were pointing at 1.6, both in the pom and from the project properties page in Eclipse. No amount of Maven Update Project and/or refreshing solved this.
Finally I tried closing the project and re-opening it, and this seemed to fix it! HTH
You have compiled your Java class with JDK 7 and you are trying to run same class on JDK 6 .
Install JDK 7.0.55 and set the Java for Eclipse for JDK 7.0.55.
Build the project with JDK 7.0.55 by configuring on build path JDK 7.0.55.
Set the compiler in Eclipse for JDK 7.0.55 by menu Windows -> Preferences -> Java -> Compiler - choose 1.7.
This question already has answers here:
How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version
(51 answers)
Closed 6 years ago.
Pictures:
Command Prompt showing versions
Picture of error
Hello.java
import java.applet.Applet;
import java.awt.*;
public class Hello extends Applet {
// Java applet to draw "Hello World"
public void paint (Graphics page) {
page.drawString ("Hello World!", 50, 50);
}
}
Hello.html
<HTML>
<HEAD>
<TITLE>HelloWorld Applet</TITLE>
</HEAD>
<BODY>
<APPLET CODE="Hello.class" WIDTH=300 HEIGHT=150>
</APPLET>
</BODY>
</HTML>
Error
Hello : Unsupported major.minor version 52.0
What may the problem be?
The issue is because of Java version mismatch. Referring to the JVM specification the following are the major versions of classfiles for use with different versions of Java. (As of now, all versions support all previous versions.)
Java SE version
Major version
1.0.2
45
1.1
45 (Not a typo, same version)
1.2
46
1.3
47
1.4
48
5.0
49
6
50
7
51
8
52
9
53
10
54
11
55
12
56
13
57
14
58
15
59
16
60
These are the assigned major numbers. The error regarding the unsupported major.minor version is because during compile time you are using a higher JDK and a lower JDK during runtime.
Thus, the 'major.minor version 52.0' error is possibly because the jar was compiled in JDK 1.8, but you are trying to run it using a JDK 1.7 environment. The reported number is the required number, not the number you are using. To solve this, it's always better to have the JDK and JRE pointed to the same version.
In IntelliJ IDEA,
Go to Maven Settings → Maven → Importing. Set the JDK for importer to 1.8.
Go to Maven Settings → Maven → Runner. Set the JRE to 1.8.
Go to menu File* → Project Structure → SDKs. Make sure the JDK home path is set to 1.8.
Restart IntelliJ IDEA.
Another approach which might help is by instructing IntelliJ IDEA which JDK version to start up with.
Go to: /Applications/IntelliJ\ IDEA\ 15\ CE.app/Contents/Info.plist
and replace the JVM version with:
<key>JVMVersion</key>
<string>1.8*</string>
The smart way to fix that problem is to compile using the latest SDK and use the cross compilation options when compiling. To use the options completely correctly requires the rt.jar of a JRE (not JDK) of the target version.
Given the nature of that applet, it looks like it could be compiled for use with Java 1.1 meaning you'd use javac -target 1.1.
You will need to change your compiler compliance level back to 1.7 in your IDE.
This can be done in the preferences settings of your IDE. For example, in Eclipse go to menu Windows → Preferences, select Java, and expand it. Then select Compiler and change the compliance level to 1.7. I am sure this will work from there.
You must run and compile your application with the same version of Java.
If you're using Eclipse you should do 2 things:
In Eclipse, click on "Window > Preferences", and in the window that appears, on the left side, under "Java", click on "Installed JREs", click on "Add..." and navigate to the folder that contains the JDK.
Right-click on your project and click on "Properties", in the window that appears, on the left side, click on "Java Compiler" and uncheck "Use compliance from execution environment on the Java Build Path", this allows you to choose in the the list "Compiler compilance level" the same version that you set in the previous step.
You need to upgrade your Java version to Java 8.
Download latest Java archive
Download latest Java SE Development Kit 8 release from its official download page or use following commands to download from the shell.
For 64 bit
# cd /opt/
# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u51-b16/jdk-8u51-linux-x64.tar.gz"
# tar xzf jdk-8u51-linux-x64.tar.gz
For 32 bit
# cd /opt/
# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u51-b16/jdk-8u51-linux-i586.tar.gz"
# tar xzf jdk-8u51-linux-i586.tar.gz
Note: If the above wget command doesn’t not work for you, watch this example video to download the Java source archive using the terminal.
Install Java with alternatives
After extracting the archive file, use the alternatives command to install it. The alternatives command is available in the chkconfig package.
# cd /opt/jdk1.8.0_51/
# alternatives --install /usr/bin/java java /opt/jdk1.8.0_51/bin/java 2
# alternatives --config java
At this point Java 8 has been successfully installed on your system. We also recommend to setup javac and jar commands path using alternatives:
# alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_51/bin/jar 2
# alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_51/bin/javac 2
# alternatives --set jar /opt/jdk1.8.0_51/bin/jar
# alternatives --set javac /opt/jdk1.8.0_51/bin/javac
Check installed Java version
Check the installed version of Java using the following command.
root#tecadmin ~# java -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
Configuring Environment Variables
Most of Java-based applications use environment variables to work. Set the Java environment variables using the following commands:
Setup JAVA_HOME Variable
# export JAVA_HOME=/opt/jdk1.8.0_51
Setup JRE_HOME Variable
# export JRE_HOME=$JAVA_HOME/jre
Setup PATH Variable
# export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
Note that the change to the PATH variable put the new Java bin folders first so that they override any existing java/bins in the path. It is a bit sloppy to leave two java/bin folders in your path so you should be advised to clean those up as a separate task.
Also, put all above environment variables in the /etc/environment file for auto loading on system boot.
I had the same problem... a JDK and plug-in version conflict.
I compiled using 1.8 ... the latest one, and that message started to appear.
So I've searched for the JRE 7 (http://www.oracle.com/technetwork/java/javase/downloads/server-jre7-downloads-1931105.html)... and installed it... again...
Now 1.8 and 1.7 in the same computer.
Using NetBeans, and compiling, and targeting to version 1.7, fixed my problem.
If you have a problem in Android Studio and you have installed Android N, change the Android rendering version with an older one and the problem will disappear.
If you're using the NetBeans IDE, right click on the project and choose Properties and go to sources, and you can change the Source/Binary Format to a lower JDK version.
Unsupported major.minor version 52.0 comes when you are trying to run a class compiled using Java 1.8 compiler into a lower JRE version e.g. JRE 1.7 or JRE 1.6. Simplest way to fix this error is install the latest Java release i.e. Java 8 and run your program.
Read more: http://javarevisited.blogspot.com/2015/05/fixing-unsupported-majorminor-version.html#ixzz4AVD4Evgv
It happens when you compile your projects on higher version of java(say jdk 1.8) and then run it on a lower version (say jdk 1.7).
If you have JRE-1.7 library in your project path then ,
1.Right click on project
2.Go to Properties
3.Select Project Facets
4.Find Java in rows and then choose version (say 1.7) if using JRE-1.7
5.Click Apply and run your project.
I solved my problem by removing old versions of JRE and installing JRE 8.
I could solve the same problem using the below solution.
In my project, I added a JAR file which were created in Java 8. And my project was referring to JRE 7. When I changed project JRE to 8, my problem was solved.
Steps:
In Eclipse, right click on the project name in project explorer → Build path → Libraries → click on JRE version → click Edit → Installed JRE → Add → Standerd VM → select JRE home click-path (path should be localePath\java\jdk1.8.0_25\jre) → provide name → Save → select same JRE for project → Finish → OK. Refresh/build project once → try to run your Java file. It should work.
I had Java 1.7 & 1.8 installed (with SBT 2.4 that requires Java 1.8).
Even though my project was linked to Java 1.8, I had to change the JAVA_HOME environment variable to point 1.8.
Finally, problem solved.
If you are using Eclipse, make sure your menu Project → Properties → Java build path → libraries → JRE system library matches your project requirements (as shown in the image).
All you need to do to solve the problem is... to make sure your version of Java is the same for both compiling and running. No matter what tools or IDEs you are using.
If you are using Linux and you have different versions of Java installed, use the following command:
sudo update-alternatives --config java
This will give a quick way of switching between the Java versions installed on the system. By choosing Java 8 I will solve your problem.
This occurred to me when I installed a fresh Java 1.8, but left the old command line interpreter open.
It had an old path and kept on executing the application with Java 1.7 whereas project was already built with Java 1.8.
If your JDK version is right. Another reason that may cause this error is that your Android Studio is in a low version, but your Gradle version is too high. Upgrade your IDE to a newer version may help this.
Upgrade your Andorra version to JDK 1.8.
This is a version mismatch that your compiler is looking for Java version 8 and you have Java version 7.
You can run an app build in version 7 in version 8, but you can't do vice versa because when it comes to higher levels, versions are embedded with more features, enhancements rather than previous versions.
Download JDK version from this link
And set your JDK path for this
You need to use JDK 1.7.0 rather than JDK 1.8.0.
To make sure it, you need to delete JDK 1.8.0 on your computer.
If you use Mac, you need to delete:
/Library/Java/JavaVirtualMachines/jdk.jdk
/Library/PreferencePanes/JavaControlPanel.prefPane
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin
Then, you need to reinstall JDK 1.7.0, and you will succeed to generate the .jar file.
You may want to check your Run Configurations setting if you're using Eclipse v4.4 (Luna) and have already completed all steps mentioned above.
There could be several possibilities that cause this error. The root cause is a mismatch of the project require compilation in JDK1.8/JRE8 while the environment compiler is JDK1.7/JRE7.
You can check my blog post to go through all your settings are correct.
None of these answers helped me, but I found a solution.
I had a webproject used in Wildfly 8.2, built with Maven, source and target was set to 1.8 on maven-compiler-plugin, as well as all Eclipse and Maven settings were set to Java 1.8.
The problem was that Wildfly 8.2 cannot handle Java 1.8, so I had to set everything to 1.7 and it worked.
Just want to add this. I had this problem today. Adjusted the settings in my project, rebuilt, and same problem. I had (incorrectly) assumed that changing the settings in my project (Eclipse) would cause the projects on which my project depends to be recompiled also.
Adjusting the settings to all of the projects up the dependency tree solved the problem.
Just go to http://java.com/en/download/ and update your version of JRE
If you are using IntelliJ IDEA, go to Project Structure (Ctrl + Alt + Shift + S), and you can change your project's JDK.
I ran into this issue in Eclipse on Mac OS X v10.9 (Mavericks). I tried many answers on Stack Overflow ... finally, after a full day I *installed a fresh version of the Android SDK (and updated Eclipse, menu Project → Properties → Android to use the new path)*.
I had to get SDK updates, but only pulling down those updates I thought were necessary, avoiding APIs I were not working with (like Wear and TV) .. and that did the trick. Apparently, it seems I had corrupted my SDK somewhere along the way.
BTW .. I did see the error re-surface with one project in my workspace, but it seemed related to an import of appcompat-7, which I was not using. After rm-ing that project, so far haven't seen the issue resurface.
This question already has answers here:
How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version
(51 answers)
Closed 6 years ago.
Pictures:
Command Prompt showing versions
Picture of error
Hello.java
import java.applet.Applet;
import java.awt.*;
public class Hello extends Applet {
// Java applet to draw "Hello World"
public void paint (Graphics page) {
page.drawString ("Hello World!", 50, 50);
}
}
Hello.html
<HTML>
<HEAD>
<TITLE>HelloWorld Applet</TITLE>
</HEAD>
<BODY>
<APPLET CODE="Hello.class" WIDTH=300 HEIGHT=150>
</APPLET>
</BODY>
</HTML>
Error
Hello : Unsupported major.minor version 52.0
What may the problem be?
The issue is because of Java version mismatch. Referring to the JVM specification the following are the major versions of classfiles for use with different versions of Java. (As of now, all versions support all previous versions.)
Java SE version
Major version
1.0.2
45
1.1
45 (Not a typo, same version)
1.2
46
1.3
47
1.4
48
5.0
49
6
50
7
51
8
52
9
53
10
54
11
55
12
56
13
57
14
58
15
59
16
60
These are the assigned major numbers. The error regarding the unsupported major.minor version is because during compile time you are using a higher JDK and a lower JDK during runtime.
Thus, the 'major.minor version 52.0' error is possibly because the jar was compiled in JDK 1.8, but you are trying to run it using a JDK 1.7 environment. The reported number is the required number, not the number you are using. To solve this, it's always better to have the JDK and JRE pointed to the same version.
In IntelliJ IDEA,
Go to Maven Settings → Maven → Importing. Set the JDK for importer to 1.8.
Go to Maven Settings → Maven → Runner. Set the JRE to 1.8.
Go to menu File* → Project Structure → SDKs. Make sure the JDK home path is set to 1.8.
Restart IntelliJ IDEA.
Another approach which might help is by instructing IntelliJ IDEA which JDK version to start up with.
Go to: /Applications/IntelliJ\ IDEA\ 15\ CE.app/Contents/Info.plist
and replace the JVM version with:
<key>JVMVersion</key>
<string>1.8*</string>
The smart way to fix that problem is to compile using the latest SDK and use the cross compilation options when compiling. To use the options completely correctly requires the rt.jar of a JRE (not JDK) of the target version.
Given the nature of that applet, it looks like it could be compiled for use with Java 1.1 meaning you'd use javac -target 1.1.
You will need to change your compiler compliance level back to 1.7 in your IDE.
This can be done in the preferences settings of your IDE. For example, in Eclipse go to menu Windows → Preferences, select Java, and expand it. Then select Compiler and change the compliance level to 1.7. I am sure this will work from there.
You must run and compile your application with the same version of Java.
If you're using Eclipse you should do 2 things:
In Eclipse, click on "Window > Preferences", and in the window that appears, on the left side, under "Java", click on "Installed JREs", click on "Add..." and navigate to the folder that contains the JDK.
Right-click on your project and click on "Properties", in the window that appears, on the left side, click on "Java Compiler" and uncheck "Use compliance from execution environment on the Java Build Path", this allows you to choose in the the list "Compiler compilance level" the same version that you set in the previous step.
You need to upgrade your Java version to Java 8.
Download latest Java archive
Download latest Java SE Development Kit 8 release from its official download page or use following commands to download from the shell.
For 64 bit
# cd /opt/
# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u51-b16/jdk-8u51-linux-x64.tar.gz"
# tar xzf jdk-8u51-linux-x64.tar.gz
For 32 bit
# cd /opt/
# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u51-b16/jdk-8u51-linux-i586.tar.gz"
# tar xzf jdk-8u51-linux-i586.tar.gz
Note: If the above wget command doesn’t not work for you, watch this example video to download the Java source archive using the terminal.
Install Java with alternatives
After extracting the archive file, use the alternatives command to install it. The alternatives command is available in the chkconfig package.
# cd /opt/jdk1.8.0_51/
# alternatives --install /usr/bin/java java /opt/jdk1.8.0_51/bin/java 2
# alternatives --config java
At this point Java 8 has been successfully installed on your system. We also recommend to setup javac and jar commands path using alternatives:
# alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_51/bin/jar 2
# alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_51/bin/javac 2
# alternatives --set jar /opt/jdk1.8.0_51/bin/jar
# alternatives --set javac /opt/jdk1.8.0_51/bin/javac
Check installed Java version
Check the installed version of Java using the following command.
root#tecadmin ~# java -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
Configuring Environment Variables
Most of Java-based applications use environment variables to work. Set the Java environment variables using the following commands:
Setup JAVA_HOME Variable
# export JAVA_HOME=/opt/jdk1.8.0_51
Setup JRE_HOME Variable
# export JRE_HOME=$JAVA_HOME/jre
Setup PATH Variable
# export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
Note that the change to the PATH variable put the new Java bin folders first so that they override any existing java/bins in the path. It is a bit sloppy to leave two java/bin folders in your path so you should be advised to clean those up as a separate task.
Also, put all above environment variables in the /etc/environment file for auto loading on system boot.
I had the same problem... a JDK and plug-in version conflict.
I compiled using 1.8 ... the latest one, and that message started to appear.
So I've searched for the JRE 7 (http://www.oracle.com/technetwork/java/javase/downloads/server-jre7-downloads-1931105.html)... and installed it... again...
Now 1.8 and 1.7 in the same computer.
Using NetBeans, and compiling, and targeting to version 1.7, fixed my problem.
If you have a problem in Android Studio and you have installed Android N, change the Android rendering version with an older one and the problem will disappear.
If you're using the NetBeans IDE, right click on the project and choose Properties and go to sources, and you can change the Source/Binary Format to a lower JDK version.
Unsupported major.minor version 52.0 comes when you are trying to run a class compiled using Java 1.8 compiler into a lower JRE version e.g. JRE 1.7 or JRE 1.6. Simplest way to fix this error is install the latest Java release i.e. Java 8 and run your program.
Read more: http://javarevisited.blogspot.com/2015/05/fixing-unsupported-majorminor-version.html#ixzz4AVD4Evgv
It happens when you compile your projects on higher version of java(say jdk 1.8) and then run it on a lower version (say jdk 1.7).
If you have JRE-1.7 library in your project path then ,
1.Right click on project
2.Go to Properties
3.Select Project Facets
4.Find Java in rows and then choose version (say 1.7) if using JRE-1.7
5.Click Apply and run your project.
I solved my problem by removing old versions of JRE and installing JRE 8.
I could solve the same problem using the below solution.
In my project, I added a JAR file which were created in Java 8. And my project was referring to JRE 7. When I changed project JRE to 8, my problem was solved.
Steps:
In Eclipse, right click on the project name in project explorer → Build path → Libraries → click on JRE version → click Edit → Installed JRE → Add → Standerd VM → select JRE home click-path (path should be localePath\java\jdk1.8.0_25\jre) → provide name → Save → select same JRE for project → Finish → OK. Refresh/build project once → try to run your Java file. It should work.
I had Java 1.7 & 1.8 installed (with SBT 2.4 that requires Java 1.8).
Even though my project was linked to Java 1.8, I had to change the JAVA_HOME environment variable to point 1.8.
Finally, problem solved.
If you are using Eclipse, make sure your menu Project → Properties → Java build path → libraries → JRE system library matches your project requirements (as shown in the image).
All you need to do to solve the problem is... to make sure your version of Java is the same for both compiling and running. No matter what tools or IDEs you are using.
If you are using Linux and you have different versions of Java installed, use the following command:
sudo update-alternatives --config java
This will give a quick way of switching between the Java versions installed on the system. By choosing Java 8 I will solve your problem.
This occurred to me when I installed a fresh Java 1.8, but left the old command line interpreter open.
It had an old path and kept on executing the application with Java 1.7 whereas project was already built with Java 1.8.
If your JDK version is right. Another reason that may cause this error is that your Android Studio is in a low version, but your Gradle version is too high. Upgrade your IDE to a newer version may help this.
Upgrade your Andorra version to JDK 1.8.
This is a version mismatch that your compiler is looking for Java version 8 and you have Java version 7.
You can run an app build in version 7 in version 8, but you can't do vice versa because when it comes to higher levels, versions are embedded with more features, enhancements rather than previous versions.
Download JDK version from this link
And set your JDK path for this
You need to use JDK 1.7.0 rather than JDK 1.8.0.
To make sure it, you need to delete JDK 1.8.0 on your computer.
If you use Mac, you need to delete:
/Library/Java/JavaVirtualMachines/jdk.jdk
/Library/PreferencePanes/JavaControlPanel.prefPane
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin
Then, you need to reinstall JDK 1.7.0, and you will succeed to generate the .jar file.
You may want to check your Run Configurations setting if you're using Eclipse v4.4 (Luna) and have already completed all steps mentioned above.
There could be several possibilities that cause this error. The root cause is a mismatch of the project require compilation in JDK1.8/JRE8 while the environment compiler is JDK1.7/JRE7.
You can check my blog post to go through all your settings are correct.
None of these answers helped me, but I found a solution.
I had a webproject used in Wildfly 8.2, built with Maven, source and target was set to 1.8 on maven-compiler-plugin, as well as all Eclipse and Maven settings were set to Java 1.8.
The problem was that Wildfly 8.2 cannot handle Java 1.8, so I had to set everything to 1.7 and it worked.
Just want to add this. I had this problem today. Adjusted the settings in my project, rebuilt, and same problem. I had (incorrectly) assumed that changing the settings in my project (Eclipse) would cause the projects on which my project depends to be recompiled also.
Adjusting the settings to all of the projects up the dependency tree solved the problem.
Just go to http://java.com/en/download/ and update your version of JRE
If you are using IntelliJ IDEA, go to Project Structure (Ctrl + Alt + Shift + S), and you can change your project's JDK.
I ran into this issue in Eclipse on Mac OS X v10.9 (Mavericks). I tried many answers on Stack Overflow ... finally, after a full day I *installed a fresh version of the Android SDK (and updated Eclipse, menu Project → Properties → Android to use the new path)*.
I had to get SDK updates, but only pulling down those updates I thought were necessary, avoiding APIs I were not working with (like Wear and TV) .. and that did the trick. Apparently, it seems I had corrupted my SDK somewhere along the way.
BTW .. I did see the error re-surface with one project in my workspace, but it seemed related to an import of appcompat-7, which I was not using. After rm-ing that project, so far haven't seen the issue resurface.