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

时间:2011-05-16 21:20:16

标签: hibernate jsf

我正在使用Hibernate开发一个JSF webapp。我测试了一个主类,我可以插入数据库,但我不能将我的webapp部署到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

这是如何引起的?如何解决?

1 个答案:

答案 0 :(得分:1)

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

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