How To Fix Java Unsupported major.minor Version 51.0 Exception

When you run a program in Eclipse or command line. You may encounter the following exception java.lang.UnsupportedClassVersionError: Unsupported major.minor version 51.0. This is because your java class compiler version is bigger than the java class runtime version. In my environment, my java runtime version is 1.6, but my eclipse java compiler version is 1.8. So I need to upgrade my eclipse java runtime JDK from version 1.6 to 1.8.

1. The Error java.lang.UnsupportedClassVersionError: Unsupported major.minor version 51.0 Stack Trace.

Below is the java.lang.UnsupportedClassVersionError: Unsupported major.minor version 51.0 error stack trace output in my eclipse console.

java.lang.UnsupportedClassVersionError: com/dev2qa/java/basic/CheckLeapYear : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Exception in thread "main"

2. How To Find The Java Class Used Java Runtime Version.

If you use eclipse, you can open your java class source file in the eclipse code editor. Right-click anywhere in the java source code editor, then click the Run As —> Run Configurations… menu item in the popup menu list.

In the Run Configurations pop-up dialog window, click the JRE tab on the right panel. Then you can find the java class used runtime JRE version in the tab content Runtime JRE: area.

There are 3 choices for you to choose the runtime JRE. You can choose either Project execution environment, Execution environment from the Environments drop-down list, or Alternate JRE from the Installed JREs… drop-down list.

To fix this error, you should make sure the java runtime JDK version you selected here is equal to or bigger than the eclipse project java compiler version.

3. How To Find The Eclipse Project Used Java Compiler Version.

Select the eclipse project in the eclipse left side Project Explorer panel, click the Project —> Properties menu item at the eclipse top menu bar. In the popup project Properties dialog window, click the Java Compiler menu item on the left side.

Check the checkbox Enable project specific settings. Uncheck the checkbox  JDK Compliance —> Use compliance from execution environment ‘JavaSe-1.8’ on the ‘Java Build Path’.

Select the java compiler JDK version ( should smaller than or equal to the java runtime JDK version ) from the Compiler compliance level drop-down list. Click the OK button to save the changes.

4. How To Add Alternate JDK Version In Eclipse.

Open eclipse and click Window —> Preferences menu item in the eclipse toolbar. Click Java —> Installed JREs in the left panel of the popup eclipse Preferences window.

Click the Add button on the right panel, then it will popup the select JRE Type dialog. In the Installed JRE Types list, select the Standard VM item, and click the Next button.

Click the Directory… button after the JRE home input textbox to choose the JDK installed directory ( not JRE installed directory ). Click the Finish button in the JRE Definition dialog window to complete the JDK add process.

In the Installed JREs list window, check the checkbox before the JDK you just added, then click the OK button to save the changes.

5. Video Demo For This Article.

You can see this example demo video below.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.