-->

Unsupported major.minor version 51.0 error after m

2019-02-19 05:18发布

问题:

I am getting a Unsupported major.minor version 51.0 error after moving from IntelliJ IDEA JBoss to MyEclipse Tomcat.

Everything was working great under IntelliJ IDEA and JBoss and now we are moving to MyEclipse and Tomcat 6..

I am getting:

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

can someone please tell me how to fix this issue

回答1:

This happens when you compile the code in a higher version of the JDK than you are using at runtime.

You can set the compiler version here:

Project -> Properties -> Java Compiler


回答2:

It seems that the version of JRE under tomcat is newer than the one used to compile the code.

To fix the actual problem you should try to either update your JRE pointing in Tomcat with newer version Java JRE or specify target parameter to the Java compiler to instruct the compiler to create code compatible with earlier Java versions in Eclipse.