Tag Archives: Java.lang.Unsupported dClassVersionError

[Java. Lang. unsupported classversionerror] version inconsistency error

All error information of this error:

 1 java.lang.UnsupportedClassVersionError: org/apache/lucene/store/Directory : Unsupported major.minor version 51.0
 2  at java.lang.ClassLoader.defineClass1(Native Method)
 3  at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
 4  at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
 5  at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
 6  at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
 7  at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
 8  at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
 9  at java.security.AccessController.doPrivileged(Native Method)
10  at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
11  at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
12  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
13  at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
14 Exception in thread "main" 

Read the error message because the jar package version used is incorrect. What is this 51.0?

Different versions of JDK compile different class files. By looking at the first few bytes of the analysis class file, you can find the corresponding relationship. For detailed reference, there may be differences between subtle versions:

1 J2SE 7 = 51 (0x33 hex),
2 J2SE 6.0 = 50 (0x32 hex),
3 J2SE 5.0 = 49 (0x31 hex),
4 JDK 1.4 = 48 (0x30 hex),
5 JDK 1.3 = 47 (0x2F hex),
6 JDK 1.2 = 46 (0x2E hex),
7 JDK 1.1 = 45 (0x2D hex).

Take a look at the screenshot of error reporting:

Originally, my eclipse JDK is 1.6, but the jar package clearly requires 1.7. Of course, there will be an error!

So, how to correct it?Download the 1.7 JDK.

Right click the project and click properties

Click JRE library

Modify JDK version

Finally, the compilation succeeded!