2013-02-09 299 views
1

我試圖檢索webpage.But數據庫和顯示所有的元素現在是生產錯誤HTTP Status 500 - Servlet execution threw an exception。任何人都可以告訴我如何解決這個錯誤。請幫幫我。HTTP狀態500 - Servlet的執行引發了異常在tomcat7

堆棧跟蹤:

javax.servlet.ServletException: Servlet execution threw an exception 
    root cause 

java.lang.NoClassDefFoundError: com/google/gson/JsonObject 
skypark.RetriveIm.doGet(RetriveIm.java:64) 
javax.servlet.http.HttpServlet.service(HttpServlet.java:621) 
javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 
    root cause 

java.lang.ClassNotFoundException: com.google.gson.JsonObject 
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714) 
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559) 
skypark.RetriveIm.doGet(RetriveIm.java:64) 
javax.servlet.http.HttpServlet.service(HttpServlet.java:621) 
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)               

完整的源代碼在this問題

這是#64Gson gson=new Gson(); 請幫我........謝謝... 。

+0

的異常堆棧跟蹤本身就說明這到底是怎麼下怎麼回事引擎蓋 - 'java.lang.NoClassDefFoundError:com/google/gson/JsonObject'。 – Lion 2013-02-09 11:28:15

+0

如何在tomcat服務器上安裝/部署servlet代碼? – 2013-02-09 14:50:41

回答

1

編譯對罐子提供com.google.gson.JsonObject(或相關),但在運行時沒有部署它。它需要進行部署,以便類運行時可以由類加載器找到/加載該類。

+0

你說得對。我在eclipse中工作,告訴我如何解決這個問題.... – james 2013-02-09 11:29:42

+0

我在我的項目庫中添加了gson 2.2 jar文件。請告訴我爲什麼這顯示錯誤。 – james 2013-02-09 12:12:55

1

爲Gson添加庫給你的classpath。無論是你的Web應用程序(WEB-INF/lib)還是你的AS的類路徑。

+0

我在我的項目庫中添加了gson 2.2 jar文件。請告訴我爲什麼這顯示錯誤。 – james 2013-02-09 12:13:30

+0

如果類com/google/gson/JsonObject存在,請檢查jar的內容。如果沒有下載其他版本,例如2.1(http://www.jarvana.com/jarvana/view/com/google/code/gson/gson/2.1/gson-2.1-sources.jar!/com /google/gson/JsonObject.java?format=ok)。 – 2013-02-09 20:01:49

+0

btw。 「將jar添加到項目庫」是什麼意思?您必須將其添加到war文件的'WEB-INF/lib'目錄或Tomcat的公共lib路徑中。 – 2013-02-09 20:04:12

1

假設你使用Eclipse和配置爲動態Web項目的項目右鍵單擊項目 - >選擇configure build path - >現在click on add jars button - >和select the Gson jar - >點擊OK

Republish項目和restart服務器。

否則jar添加到WEB-INF\lib directory戰爭中

或者直接進入在tomcat部署的位置,但在提到同一個目錄

相關問題