Bad version number in .class file 错误原因

来源:互联网 发布:java分布式框架有哪些 编辑:程序博客网 时间:2024/04/30 09:19
 

在用eclipse+myeclipse做Web service实例时,编译总是提示“Bad version number in .class file”,导致执行web service deploy总会提示错误,花了好大劲才知道原因是“Java Compile Level和指定编译的JRE两者间的版本不一致导致'”按以下步骤修改eclipse设置即可恢复正常。

eclisep--preferences--java--Compiler里面的Compiler compilance settings 要选和jdk一样的版本,jdk1.5要选5.0

出现的错误如下: java.lang.UnsupportedClassVersionError: Bad version number in .class file  at java.lang.ClassLoader.defineClass1(Native Method)  at java.lang.ClassLoader.defineClass(Unknown Source)  at java.security.SecureClassLoader.defineClass(Unknown Source)  at java.net.URLClassLoader.defineClass(Unknown Source)  at java.net.URLClassLoader.access$100(Unknown Source)  at java.net.URLClassLoader$1.run(Unknown Source)  at java.security.AccessController.doPrivileged(Native Method)  at java.net.URLClassLoader.findClass(Unknown Source)  at java.lang.ClassLoader.loadClass(Unknown Source)



This error is reported when someone is trying to deploy war whichcontains java files which have been compiled by jdk version which islower than the jdk version which the tomcat uses.For example wecompiled java files using jdk 1.4 and now we are trying to deploy it intomcat which uses jdk 1.5.
Solution is either make tomcat uses older version of jdk or againcreate java class files using the version that is being used by tomcat.