The error of Java. Lang. unsupportedclassversionerror occurs because the Java class file compiled by JDK of a higher version is used to run on the JVM of a lower version.
Because the format of the class file generated by JDK of a higher version may be different from that of JDK of a lower version. Class. In this way, the. Class file cannot be interpreted and executed in earlier versions of JVM, and a class version error not supported by Java. Lang. unsupportedclassversionerror will be thrown.
This error is especially evident in versions earlier than JDK 5 and JDK 5. Because JDK 5 has made a lot of enhancements in the Java syntax and introduced some new elements of the. Class file, leading to the failure to interpret and execute the. Class file in the old version of JVM. Even if this class does not use any new elements of JDK 5, The. Class file generated by JDK 5 and jdk1.4 and its previous JVM cannot be identified!
Therefore, jdk1.4 is the most widely used one. JDK 5 is unavailable for many software and projects.
There are two solutions:
First:
A developer named Toby reyelts decided to remove the JDK 5.0 compiler restrictions. The result is an open-source retroweaver project (see http://www-128.ibm.com/developerworks/cn/java/j-cwt07065/#resources#resources ). Weaver uses classworking technology to modify the binary class representation generated by the JDK 5.0 compiler so that these classes can be used with early JVMs.
It modifies the. Class file generated by JDK 5 to the. Class file that can be run by jvm1.4 and earlier versions.
Currently, using the new IDE Editor may cause java. Lang. unsupportedclassversionerror.
For example, eclipse3.2 + myeclipse5.0 is the new IDE tool. Go to preference --- Java --- compiler. We can see that the default compliance level of the compiler is 5.0. Here we change it to 1.4 because the software we use needs to run on jdk1.4 JVM.
In JRE installed in the same configuration area, do not install JRE. Instead, install JDK, and specify JDK 1.4 or 1.5. Or use jdk1.4.
Under myeclipse-application server, specify Tomcat 5. Specify tomcat to use jdk1.4.
In this way, jdk1.4 is used to compile and run the program. It is also possible to specify jdk5. However, it is absolutely impossible to use JDK 5 to compile the program and run the program on JDK. This will throw a class version error that is not supported by Java. Lang. unsupportedclassversionerror.
In this case, whether it is the war package generated by eclipse or the war package generated by the ant file, JDK 5 is used for compilation, and an error occurs during the runtime, and the application cannot be started. If you view the Tomcat log file, you will see that Java. Lang. unsupportedclassversionerror has occurred!
Second:
1. Right-click the project file and choose Properties ),
2. Select build --> JAVA in the Properties window. There are four drop-down boxes in the options on the right to see the compilation options,
3. You can skip compiler and debug option. You only need to select the appropriate JDK version in Languege features and target VM. Then, make sure everything is OK.
The attachment contains the configuration image.
-----------------------------------------------------------
If all Java sdks are selected in the target Vm, your class files can be run on the VMS that use JDK. (This is what jbuilder2006 says in help, it is estimated that only a few of them are still using JDK :-)
2.
Eclipse3.1 also has the same problem. In this case, you only need to build the JDK used by the project and the JDK you have installed.
Step: Right-click your project and choose Properties> Java compiler to set the appropriate version !!