JSF 2.0 和 Hibernate 错误

发布于 2024-09-14 19:31:18 字数 2155 浏览 6 评论 0原文

我将应用程序部署到官方服务器并开始收到此错误:

堆栈跟踪: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏见 2024-09-21 19:31:18

我认为您的类位于类路径上,但在尝试加载类时ClassLoader遇到错误(如消息所示)。当类具有使用 Class 无法被 ClassLoader 找到的 Class 的静态块或静态成员时,通常会发生这种情况。

在生成的 HibernateUtil.java 的特定情况下,它应该具有如下内容:

static {
  URL myurl = Thread.currentThread().getContextClassLoader().getResource("/some/path/to/hibernate.cfg.xml");
  sessionFactory = new Configuration().configure(myurl).buildSessionFactory();
}

因此:

  • 确保 hibernate 配置文件存在是预期的。
  • 确保 Hibernate jar 存在于目标计算机的类路径中。
  • 也许在静态块中添加一个 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 a Class that can't found by the ClassLoader.

In the particular case of this generated HibernateUtil.java, it should have something like this:

static {
  URL myurl = Thread.currentThread().getContextClassLoader().getResource("/some/path/to/hibernate.cfg.xml");
  sessionFactory = new Configuration().configure(myurl).buildSessionFactory();
}

So:

  • Make sure the hibernate configuration file is present were expected.
  • Make sure the Hibernate jars are present on the class path of the target machine.
  • Maybe add a try { ... } catch (Throwable t) { ... } in your static block to log the error.
つ可否回来 2024-09-21 19:31:18

您应该阅读 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文