今天在合并项目后启动tomcat的时候,发现窗口中报了如下错误:
java.lang.NoClassDefFoundError: org/hibernate/cfg/HbmBinder$SecondPass
最后上网查了下,发现有这个问题的人还真不少,一些没碰到过这个问题的人就说是因为找不到这个类,但是解决方法都没有明说,要么就是删除hibernate-annotations.jar,但是我的lib里没有这个类,很是困扰。
然后发现有的说解决方法就是下最新的hibernate-annotations.jar的包~,这确实能够解决问题,然后覆盖下面的第四个目录下的这个包文件即可
但却不是最根本的解决方法,这个问题其实很奇怪,关键就在于Junit中测试没问题,就是发布到项目中的时候,会出现这样的问题~也就是MyEclipse在发布项目文件时的问题~
于是到MyEclipse的安装目录中搜索hibernate-annotations.jar的包,发现在其中有四个hibernate-annotations.jar的包(MyEclipse6.0的版本下,5.x的不知道,可能只有三个),对比了一下他们的目录分别是:
1.D:/Program Files/MyEclipse 6.0/myeclipse/eclipse/plugins/com.genuitec.org.hibernate.eclipse_6.0.0.zmyeclipse60020070820/lib/annotations-------------[352k]
2.D:/Program Files/MyEclipse 6.0/myeclipse/eclipse/plugins/com.genuitec.eclipse.springframework_6.0.0.zmyeclipse60020070820/data/2.0/lib/hibernate -----------[267k]
3.D:/Program Files/MyEclipse 6.0/myeclipse/eclipse/plugins/com.genuitec.org.hibernate.eclipse_6.0.0.zmyeclipse60020070820/myeclipse-data/3.2/lib/entitymanager-------------[257k]
4.D:/Program Files/MyEclipse 6.0/myeclipse/eclipse/plugins/com.genuitec.eclipse.springframework_6.0.0.zmyeclipse60020070820/data/1.2/lib/dependencies/hibernate--------------------[128k]
而出错的就是第四个目录下的hibernate-annotations.jar的包,一共128k大小
观察四个包的文件大小后很明显这个问题的原因出在Spring的版本上,由于spring2.0的版本比较新,所以更新的hinbernate包也比较新,而spirng1.2的版本中,虽然包含了hibernate3.x的版本,但是却由于没有及时更新其中的hibernate包,所以导致出现了这个异常bug,也不知道是因为MyEclipse没有及时更新spring的补丁版本
问题找到了开始解决问题
把搜索到的第三个文件夹中的hibernate-annotations.jar包复制到项目的lib目录中覆盖即可,当然如果以后不想再发生这样的问题的话那就把这个文件直接覆盖搜索到的第四个目录中hibernate-annotations.jar吧,这样以后MyEclipse就再也不会发生同样的问题了~