在用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 which contains java files which have been compiled by jdk version which is lower than the jdk version which the tomcat uses.For example we compiled java files using jdk 1.4 and now we are trying to deploy it in tomcat which uses jdk 1.5.
Solution is either make tomcat uses older version of jdk or again create java class files using the version that is being used by tomcat.