How to fix java Unsupported major.minor version 51.0 Exception

When you run a program in Eclipse or command line. You may encounter following exception. java.lang.UnsupportedClassVersionError: Unsupported major.minor version 51.0.

java_lang_UnsupportedClassVersionError_Unsupported major.minor_version

This means your java compiler version is smaller than runtime version.  In my environment, my runtime is 1.7, but i use 1.6 in my eclipse compiler. So i need to upgrade my eclipse compiler from 1.6 to 1.7 as following.

  1. Click “Window —> Preferences”  in eclipse toolbar.
    change window preferences
  2. Click “Java —> Installed JREs” in left panel of the popup window.
  3. Click “Add” button in right panel.
    change java installed jre in eclipse window preferences
  4. Choose “Standard VM” in popup dialog, click “Next” button.
  5. Click “Directory” button to choose the jdk home you installed. (Not jre home, in my env, i choose: C:\Java\jdk1.7.0_25)
    select installed jdk home in eclipse window preferences installed JREs
  6. Click “Finish” button.
    click finish button to add new installed jdk
  7. Check the jdk you just installed. Click “OK”.
    check just installed jdk in eclipse window preferences
  8. Click “Project —> Properties” in toolbar.
  9. Click “Java Compiler” in left popup window.
  10. Check “Enable project specific settings”.
  11. Select the jdk you just installed(1.7 in my environment).
    change project java compiler version in eclipse
  12. Click “OK”.

Now run your program again, you will find the error disappeared.

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.