java.lang.NoClassDefFoundError: net/sf/hibernate/HibernateException

发布于 2024-11-07 18:48:33 字数 5889 浏览 0 评论 0原文

我正在使用 Hibernate 开发 JSF Web 应用程序。我用一个主类进行了测试,我可以插入数据库,但我无法将我的 web 应用程序部署到 Glassfish。它总是出现 HTTP 500 错误。这是我的代码:

faces-config:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xi="http://www.w3.org/2001/XInclude"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
 <application>
        <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
    </application>

 <managed-bean>
  <managed-bean-name>timesheetBean</managed-bean-name>
  <managed-bean-class>hibernate.timeBean.TimesheetBean</managed-bean-class>
  <managed-bean-scope>session</managed-bean-scope>
 </managed-bean>
 <navigation-rule>
  <from-view-id>/EditTimesheet.jsp</from-view-id>
 </navigation-rule>
</faces-config>

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>test</display-name>

  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
    </context-param>

    <filter>
        <display-name>RichFaces Filter</display-name>
        <filter-name>richfaces</filter-name>
        <filter-class>org.ajax4jsf.Filter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>richfaces</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>INCLUDE</dispatcher>
    </filter-mapping>


    <context-param>
        <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
        <param-value>com.sun.facelets.FaceletViewHandler</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.xhtml</param-value>
    </context-param>

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

EditTimesheet.jsp:

<%@ page language="java" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">

    <title>My JSF 'EditDepartement.jsp' starting page</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

</head>

<body>
    <f:view>
        <h:form>
        <h:inputHidden id="id" value="#{timesheetBean.currentTimesheet.id}" />
        <h:panelGrid columns="2" border="1">
            <h:inputText value="#{timesheetBean.currentTimesheet.action}">
            </h:inputText>
            <h:outputText value="heure:" />
            <h:inputText value="#{timesheetBean.currentTimesheet.heure}">
            </h:inputText>
            <h:outputText value="date:" />
            <h:inputText value="#{timesheetBean.currentTimesheet.date}">
            </h:inputText>

</h:panelGrid>
        <h:commandButton value="Save" action="listeDepartements" actionListener="#{timesheetBean.saveTimesheet}" />
        <h:commandButton value="Annuler" action="listeTimesheet"/>
    </h:form>
    </f:view>
</body>
</html>

异常是:

javax.servlet.ServletException: net/sf/hibernate/HibernateException

 root cause: java.lang.NoClassDefFoundError: net/sf/hibernate/HibernateException

这是如何引起的以及我该如何解决它吗?

I am developing a JSF webapp with Hibernate. I tested with a main class and I can insert in database, but I can't deploy my webapp to Glassfish. It always errors with HTTP 500 error. Here is my code:

faces-config:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xi="http://www.w3.org/2001/XInclude"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
 <application>
        <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
    </application>

 <managed-bean>
  <managed-bean-name>timesheetBean</managed-bean-name>
  <managed-bean-class>hibernate.timeBean.TimesheetBean</managed-bean-class>
  <managed-bean-scope>session</managed-bean-scope>
 </managed-bean>
 <navigation-rule>
  <from-view-id>/EditTimesheet.jsp</from-view-id>
 </navigation-rule>
</faces-config>

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>test</display-name>

  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
    </context-param>

    <filter>
        <display-name>RichFaces Filter</display-name>
        <filter-name>richfaces</filter-name>
        <filter-class>org.ajax4jsf.Filter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>richfaces</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>INCLUDE</dispatcher>
    </filter-mapping>


    <context-param>
        <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
        <param-value>com.sun.facelets.FaceletViewHandler</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.xhtml</param-value>
    </context-param>

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

EditTimesheet.jsp:

<%@ page language="java" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">

    <title>My JSF 'EditDepartement.jsp' starting page</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

</head>

<body>
    <f:view>
        <h:form>
        <h:inputHidden id="id" value="#{timesheetBean.currentTimesheet.id}" />
        <h:panelGrid columns="2" border="1">
            <h:inputText value="#{timesheetBean.currentTimesheet.action}">
            </h:inputText>
            <h:outputText value="heure:" />
            <h:inputText value="#{timesheetBean.currentTimesheet.heure}">
            </h:inputText>
            <h:outputText value="date:" />
            <h:inputText value="#{timesheetBean.currentTimesheet.date}">
            </h:inputText>

</h:panelGrid>
        <h:commandButton value="Save" action="listeDepartements" actionListener="#{timesheetBean.saveTimesheet}" />
        <h:commandButton value="Annuler" action="listeTimesheet"/>
    </h:form>
    </f:view>
</body>
</html>

The exeception is:

javax.servlet.ServletException: net/sf/hibernate/HibernateException

 root cause: java.lang.NoClassDefFoundError: net/sf/hibernate/HibernateException

How is this caused and how can I solve it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

左秋 2024-11-14 18:48:33

看来您正在使用 Hibernate,但没有将 Hibernate jar 和依赖项内置到您的 war 中。确保您需要的所有依赖项都已构建到 war 内的 WEB-INF/lib 目录中。

此过程取决于您构建 Web 应用程序的方式。

It appears that you are utilizing Hibernate but don't have the Hibernate jar and dependencies built into your war. Make sure that all the dependencies you need are being built into the WEB-INF/lib directory inside your war.

The process for this would depend on how you are constructing your web application.

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