【问题标题】:HTTP Status 500 - Servlet execution threw an exception In tomcat7HTTP 状态 500 - Servlet 执行在 tomcat7 中引发异常
【发布时间】:2013-01-25 02:30:30
【问题描述】:

我正在尝试检索数据库中的所有元素并显示在网页中。但现在它产生了错误HTTP Status 500 - Servlet execution threw an exception。谁能告诉我如何解决这个错误。请帮帮我。

堆栈跟踪:

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(); 请帮助我........谢谢....

【问题讨论】:

  • 异常堆栈跟踪本身表明到底发生了什么 - java.lang.NoClassDefFoundError: com/google/gson/JsonObject
  • 如何在tomcat服务器中安装/部署servlet代码?

标签: java jakarta-ee servlets tomcat7


【解决方案1】:

假设您使用 Eclipse 并且项目配置为 Dynamic Web Project 右键单击​​您的项目 --> 选择 configure build path --> 现在选择 click on add jars button --> 和 select the Gson jar --> 单击OK

Republish 项目和restart 服务器。

否则将罐子添加到WEB-INF\lib directoryinside the war

或直接进入 tomcat 中的 Deployed 位置,但在提到的同一目录中

【讨论】:

    【解决方案2】:

    您正在编译针对提供com.google.gson.JsonObject(或依赖项)的 jar,但不是在运行时部署它。它需要进行部署,以便类加载器在运行时可以找到/加载该类。

    【讨论】:

    • 我在我的项目库中添加了 gson 2.2 jar 文件。那么请告诉我为什么会显示错误。
    【解决方案3】:

    将 Gson 库添加到您的类路径中。到您的 webapp (WEB-INF/lib) 或到您的 AS 的类路径。

    【讨论】:

    • 我在我的项目库中添加了 gson 2.2 jar 文件。那么请告诉我为什么会显示错误。
    • 检查 jar 的内容是否存在 com/google/gson/JsonObject 类。如果不下载其他版本,例如 2.1 (jarvana.com/jarvana/view/com/google/code/gson/gson/2.1/…)。
    • 顺便说一句。 “将 jar 添加到项目库”是什么意思?您必须将其添加到war文件中的WEB-INF/lib目录或Tomcat的公共lib路径中。
    猜你喜欢
    • 2012-11-18
    • 2014-10-26
    • 2015-08-23
    • 2015-09-26
    • 1970-01-01
    • 2017-11-28
    • 2015-07-27
    • 2018-06-29
    • 1970-01-01
    相关资源
    最近更新 更多