2011-05-16 66 views
1

我正在用Hibernate開發一個JSF webapp。我測試了一個主類,我可以插入數據庫,但我無法將我的webapp部署到Glassfish。它始終與HTTP 500錯誤錯誤。這裏是我的代碼:java.lang.NoClassDefFoundError:net/sf/hibernate/HibernateException

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> 

的exeception是:

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

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

這是如何造成的,我該如何解決?

回答

1

看來您正在使用Hibernate,但沒有Hibernate jar和依賴關係構建到您的戰爭中。確保你所需要的所有依賴都被內置到你的war中的WEB-INF/lib目錄中。

這個過程取決於你如何構建你的web應用程序。

+0

這是我的例外:.JasperException:/test.jsp(5,57)PWC6188:絕對uri:http://richfaces.org/rich無法在web.xml或通過此部署的jar文件中解析應用程序 – user726991 2011-05-17 21:50:06

+0

這是你解決了休眠異常後的一個新問題?如果是這樣(並且這個答案幫助你解決了Hibernate異常),你能否將這個答案標記爲可接受的,這樣以後的人可以找到這個異常。然後,您可以在新問題中發佈您的新問題 - 通過這種方式,該網站提供了與特定問題的標題相關性。 – 2011-05-17 21:58:18