1

I'm trying to retrieve all elements in database and display in webpage.But now it was producing the error HTTP Status 500 - Servlet execution threw an exception. Can anyone tell me how to fix this error. Please help me.

Stack Trace :

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)                                                           

The complete source code is in this question

This is the #64 line Gson gson=new Gson(); Please help me........Thanks....

Community
  • 1
  • 1
James
  • 2,874
  • 4
  • 30
  • 55

3 Answers3

1

Add library for Gson to you classpath. Either to your webapp (WEB-INF/lib) or to the classpath of your AS.

Jiri Kremser
  • 12,471
  • 7
  • 45
  • 72
  • I have added gson 2.2 jar file in my project library. Please tell me then why this showing the error. – James Feb 09 '13 at 12:13
  • Check the content of the jar if the class `com/google/gson/JsonObject` is there. If not download some other version, where it is for instance 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). – Jiri Kremser Feb 09 '13 at 20:01
  • btw. what do you mean by "adding the jar to the project library"? You have to add it to the `WEB-INF/lib` directory in the war file or the the common lib path for Tomcat. – Jiri Kremser Feb 09 '13 at 20:04
1

You're compiling against the jar providing com.google.gson.JsonObject (or a dependent) but not deploying it at runtime. It needs to be deployed such that that class can be found/loaded by the classloader when run against.

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
  • I have added gson 2.2 jar file in my project library. Please tell me then why this showing the error. – James Feb 09 '13 at 12:12
1

Assuming your using Eclipse and the project configured as Dynamic Web Project Right click on your project --> choose configure build path --> now click on add jars button --> and select the Gson jar --> clickOK.

Republish the project and restart the server.

Else add the jar to WEB-INF\lib directoryinside the war

Or directly into the Deployed location in the tomcat , but in the same directory as mentioned

Sudhakar
  • 4,823
  • 2
  • 35
  • 42