When you run a program in Eclipse or command line. You may encounter following exception. java.lang.UnsupportedClassVersionError: Unsupported major.minor version 51.0.
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.
- Click “Window —> Preferences” in eclipse toolbar.
- Click “Java —> Installed JREs” in left panel of the popup window.
- Click “Add” button in right panel.
- Choose “Standard VM” in popup dialog, click “Next” button.
- Click “Directory” button to choose the jdk home you installed. (Not jre home, in my env, i choose: C:\Java\jdk1.7.0_25)
- Click “Finish” button.
- Check the jdk you just installed. Click “OK”.
- Click “Project —> Properties” in toolbar.
- Click “Java Compiler” in left popup window.
- Check “Enable project specific settings”.
- Select the jdk you just installed(1.7 in my environment).
- Click “OK”.
Now run your program again, you will find the error disappeared.