JSF 2.0 和 Hibernate 错误
我将应用程序部署到官方服务器并开始收到此错误:
堆栈跟踪: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:401) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
根本原因
javax.servlet.ServletException: java.lang.NoClassDefFoundError:可以 不初始化类app.HibernateUtil org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791) org.apache.jsp.ajax.search_jsp._jspService(search_jsp.java:67) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
根本原因
java.lang.NoClassDefFoundError:可以 不初始化类app.HibernateUtil app.PersistanceHelper。(PersistanceHelper.java:23) app.SearchBean.(SearchBean.java:26) org.apache.jsp.ajax.search_jsp._jspService(search_jsp.java:54) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
在部署之前,应用程序运行良好。我的 HibernateUtil 类是由 Netbeans 向导生成的。我看不出问题出在哪里。我花了一些时间在谷歌中搜索类似的问题,但找到的答案(缺少 jar、拼写错误等)不适用于此解决方案,因为它适用于我的电脑,只是不适用于官方服务器。对此有什么想法吗?如果需要的话我可以添加其余的来源。 Apache Tomcat 日志不包含任何错误。感谢您的任何帮助。
I deployed my application to the official server and started getting this error:
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:401)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)root cause
javax.servlet.ServletException:
java.lang.NoClassDefFoundError: Could
not initialize class app.HibernateUtil
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
org.apache.jsp.ajax.search_jsp._jspService(search_jsp.java:67)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)root cause
java.lang.NoClassDefFoundError: Could
not initialize class app.HibernateUtil
app.PersistanceHelper.(PersistanceHelper.java:23)
app.SearchBean.(SearchBean.java:26)
org.apache.jsp.ajax.search_jsp._jspService(search_jsp.java:54)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
Before the deployment the app worked fine. My HibernateUtil class was generated by Netbeans wizard. I cannot see where does the problem originate. I spent some time searching for the similar problem in google but the answers found (missing jars, spelling errors, etc) are not applicable in this solution as it works on my PC, just not on the official server. Any thoughts on that? I can add the rest of the sources if needed. Apache Tomcat log does not contain any errors. Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您的类位于类路径上,但在尝试加载类时
ClassLoader
遇到错误(如消息所示)。当类具有使用Class
无法被ClassLoader
找到的Class
的静态块或静态成员时,通常会发生这种情况。在生成的
HibernateUtil.java
的特定情况下,它应该具有如下内容:因此:
try { ... } catch (Throwable t) { ... }
来记录错误。I think that your class is on the classpath but the
ClassLoader
runs into an error when trying to load the class (as hinted by the message). This typically happens when the class has a static block or static members which use aClass
that can't found by theClassLoader
.In the particular case of this generated
HibernateUtil.java
, it should have something like this:So:
try { ... } catch (Throwable t) { ... }
in your static block to log the error.您应该阅读 Hibernate 发行版附带的用户文档。 Hibernate JAR 对其他 JAR 有很多运行时依赖性,例如一些 Apache Commons JAR,以及“slf4j”JAR。如果在运行时缺少这些,即使所有 Hibernate JAR 都位于正确的位置,Hibernate 将无法运行。
You should read the user documentation that comes with the Hibernate distribution. The Hibernate JARs have a bunch of runtime dependencies on other JARs, such as some of the Apache Commons ones, and the "slf4j" JARs for example. If those are missing at runtime Hibernate will not function even if all the Hibernate JARs are in the right place.