HibernateUtil照搬网上的,映射文件和类文件是用hibernate-extensions-2.1.3生成的,按书上的一步步作,最后总是 java.lang.ExceptionInInitializerError,位置在Session session = HibernateUtil.currentSession();
不知何原因
注意是NoClassDefFoundError,而不是NoClassDefFoundError: net/sf/hibernate/HibernateException。
(我手工把hibernate必须库加到lib里面了,否则就是NoClassDefFoundError: net/sf/hibernate/HibernateException,这个是毫无疑问的classpath问题)
第一次和之后运行时错误有一点不同,第一次是ExceptionInInitializerError,之后就是NoClassDefFoundError
第一次运行时错误:
javax.servlet.ServletException
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
org.apache.jsp.hibernateTest_jsp._jspService(org.apache.jsp.hibernateTest_jsp:83)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.ExceptionInInitializerError
org.zzd.listBean.getList(listBean.java:31)
org.apache.jsp.hibernateTest_jsp._jspService(org.apache.jsp.hibernateTest_jsp:60)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
之后运行时错误:
javax.servlet.ServletException
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
org.apache.jsp.hibernateTest_jsp._jspService(org.apache.jsp.hibernateTest_jsp:83)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)