java.lang.ExceptionInInitializerError(HIBERNATE问题)

第一次运行时候是这个错误!

exception

javax.servlet.ServletException: Servlet execution threw an exception

root cause

java.lang.ExceptionInInitializerError
classmate.HibernateUtil.<clinit>(HibernateUtil.java:35)
classmate.DbOperate.getUser(DbOperate.java:25)
classmate.LoginAction.execute(LoginAction.java:27)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802





程序中的对应语句是THROW语句 throw new ExceptionInInitializerError(ex);




具体如下:

try {



sessionFactory=new Configuration().configure().buildSessionFactory();


} catch (Throwable ex) {
ex.printStackTrace();// TODO: handle exception
throw new ExceptionInInitializerError(ex);
}


第二次运行时候是这个错误!

上面那个错误只出现一次!
然后一直是出现这个错误!


错误提示:Root cause

java.lang.NoClassDefFoundError

程序中对应的这句:


Session session=HibernateUtil.currentSession();



解决方法:

把HIBERNATE的JAR10个 需要的包

COPY到工程的LIB目录下
(如果你在JAVA构建路径,通过添加外部JAR包,添加了那几个必须的包,在此还要把他们COPY到工 程的LIB目录下!)


你可能感兴趣的:(Hibernate)