大神~~救命!Hibernate异常太诡异了,我见识少,望大侠帮忙!
我用的Myeclipse5.0
package com.yourcompany.struts;
import
javax.servlet.ServletException;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernatePlugIn implements PlugIn{
public String path;
public static SessionFactory sessionFactory;
public void destroy() {
// TODO 自动生成方法存根
sessionFactory.close();
}
public void init(ActionServlet arg0, ModuleConfig arg1) throws
ServletException {
// TODO 自动生成方法存根
Configuration cfg = new Configuration();
cfg.configure("/hibernate.cfg.xml");
sessionFactory = cfg.buildSessionFactory();
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public static void main(String arg[]){
HibernatePlugIn hp = new HibernatePlugIn();
try {
hp.init(null,null);
} catch (ServletException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
System.out.print("OKL");
}
}
用main()运行没什么问题,但我把上面的代码放入STRURA配置文件里做插件(PlugIn)的时候,TOMCAT启动报错:
“
java.lang.NoClassDefFoundError: org/hibernate/SessionFactory”
我是用Myeclipse自动加载的库文件,居然报这种错!怎么回事?
------解决方案--------------------
把hibernate.jar 复制到tomcat/shared/lib 目录下面