1. 程式人生 > >解決java.lang.UnsupportedClassVersionError: Bad version number in .class file問題

解決java.lang.UnsupportedClassVersionError: Bad version number in .class file問題

在啟動tomcat伺服器時, 報如下的錯誤:

org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [com.cdsccar.dao.daoimpl.BaseDaoimpl] for bean with name 'baseDao' defined in ServletContext resource [/WEB-INF/car-daoBeans.xml]: problem with class file or dependent class; nested exception is java.lang.UnsupportedClassVersionError: Bad version number in .class file。

google很多,網上說是jre版本的問題,但是我的工具編譯的環境與tomcat的一樣的,都是jre1.5(專案此前在jre1.6+tomcat6.0的環境下執行過),後來想想,我的專案是直接匯入的,web-inf下的classes檔案是通過1.6的環境編譯生成的,在部署到tomcat下沒有通過工具重新編譯來生成class檔案。在1.6的環境中生成的class不能到1.5的環境中執行,因此果斷刪除專案下web-inf資料夾的classes檔案,重新匯入eclipse中,編譯重新生成,然後部署到tomcat下,重啟tomcat,專案執行成功。

參考:http://blog.csdn.net/ty32565185/article/details/6543360