2013-02-09 300 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问题

这是#64线Gson 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部署的位置,但在提到同一个目录

相关问题