5

A friend and I are dabbling in App Engine using the Java SDK. We've put together a "Hello, World" example with no problems; however, when we try to add code to make a simple call to a webservice using the classes in com.google.api.client.http, our code compiles fine but causes a runtime error:

HTTP ERROR 500

Problem accessing /surreality. Reason:

   com/google/api/client/http/HttpTransport

Caused by:

HTTP ERROR 500

Problem accessing /surreality. Reason:

   com/google/api/client/http/javanet/NetHttpTransport

Caused by:

java.lang.NoClassDefFoundError: com/google/api/client/http/javanet/
NetHttpTransport
       at
com.surreality.scratch.SurrealityServlet.performSearch(SurrealityServlet.java:
31)
       at
com.surreality.scratch.SurrealityServlet.doGet(SurrealityServlet.java:
18)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
       at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:
511)

(...cut)

The code in question is:

package com.surreality.scratch;

import java.io.IOException;
import javax.servlet.http.*;
import java.util.List;
import com.google.api.client.googleapis.*;
import com.google.api.client.http.*;
import com.google.api.client.http.javanet.*;
import com.google.api.client.util.Key;

@SuppressWarnings("serial")
public class SurrealityServlet extends HttpServlet {

       public void doGet(HttpServletRequest req, HttpServletResponse resp)
                       throws IOException {
               resp.setContentType("text/plain");
               try {
                       this.performSearch(resp);
                       resp.getWriter().println("Here...");
               } catch (Exception e) {
                       resp.getWriter().println("Onoes!");
               }
       }

       public void performSearch(HttpServletResponse resp) throws Exception
{

               try {
                       resp.getWriter().println("Perform Search ....");
                       resp.getWriter().println("-------------------");

                       HttpTransport transport = new NetHttpTransport(); // This line
causes our servlet to implode on every request
               } catch (Exception e) {
                       resp.getWriter().println("failed");
                       throw e;
               }
       }
}

Our best guess was a discrepancy between the build classpath and the runtime classpath, but our runtime classpath seems to be OK. The HttpTransport class is in the google-api-client-1.4.1-beta.jar library, and that's included in the command line Eclipse is generating to run the project:

/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/
java -Ddatastore.default_high_rep_job_policy_unapplied_job_pct=50 -
Xmx512m -javaagent:/Applications/eclipse/plugins/
com.google.appengine.eclipse.sdkbundle_1.5.3.r37v201108301710/
appengine-java-sdk-1.5.3/lib/agent/appengine-agent.jar -
XstartOnFirstThread -Xbootclasspath/p:/Applications/eclipse/plugins/
com.google.appengine.eclipse.sdkbundle_1.5.3.r37v201108301710/
appengine-java-sdk-1.5.3/lib/override/appengine-dev-jdk-overrides.jar -
Dfile.encoding=MacRoman -classpath /Users/Arkaaito/Documents/AppEngine/
scratch/surreality/war/WEB-INF/classes:/Applications/eclipse/plugins/
com.google.appengine.eclipse.sdkbundle_1.5.3.r37v201108301710/
appengine-java-sdk-1.5.3/lib/shared/appengine-local-runtime-
shared.jar:/Applications/eclipse/plugins/
com.google.appengine.eclipse.sdkbundle_1.5.3.r37v201108301710/
appengine-java-sdk-1.5.3/lib/shared/el-api.jar:/Applications/eclipse/
plugins/com.google.appengine.eclipse.sdkbundle_1.5.3.r37v201108301710/
appengine-java-sdk-1.5.3/lib/shared/jsp/repackaged-appengine-
ant-1.7.1.jar:/Applications/eclipse/plugins/
com.google.appengine.eclipse.sdkbundle_1.5.3.r37v201108301710/
appengine-java-sdk-1.5.3/lib/shared/jsp/repackaged-appengine-ant-
launcher-1.7.1.jar:/Applications/eclipse/plugins/
com.google.appengine.eclipse.sdkbundle_1.5.3.r37v201108301710/
appengine-java-sdk-1.5.3/lib/shared/jsp/repackaged-appengine-
jasper-6.0.29.jar:/Applications/eclipse/plugins/
com.google.appengine.eclipse.sdkbundle_1.5.3.r37v201108301710/
appengine-java-sdk-1.5.3/lib/shared/jsp/repackaged-appengine-jasper-
el-6.0.29.jar:/Applications/eclipse/plugins/
com.google.appengine.eclipse.sdkbundle_1.5.3.r37v201108301710/
appengine-java-sdk-1.5.3/lib/shared/jsp/repackaged-appengine-tomcat-
juli-6.0.29.jar:/Applications/eclipse/plugins/
com.google.appengine.eclipse.sdkbundle_1.5.3.r37v201108301710/
appengine-java-sdk-1.5.3/lib/shared/jsp-api.jar:/Applications/eclipse/
plugins/com.google.appengine.eclipse.sdkbundle_1.5.3.r37v201108301710/
appengine-java-sdk-1.5.3/lib/shared/servlet-api.jar:/Applications/
eclipse/plugins/
com.google.appengine.eclipse.sdkbundle_1.5.3.r37v201108301710/
appengine-java-sdk-1.5.3/lib/user/appengine-api-1.0-sdk-1.5.3.jar:/
Applications/eclipse/plugins/
com.google.appengine.eclipse.sdkbundle_1.5.3.r37v201108301710/
appengine-java-sdk-1.5.3/lib/user/appengine-api-labs-1.5.3.jar:/
Applications/eclipse/plugins/
com.google.appengine.eclipse.sdkbundle_1.5.3.r37v201108301710/
appengine-java-sdk-1.5.3/lib/user/appengine-jsr107cache-1.5.3.jar:/
Applications/eclipse/plugins/
com.google.appengine.eclipse.sdkbundle_1.5.3.r37v201108301710/
appengine-java-sdk-1.5.3/lib/user/jsr107cache-1.1.jar:/Applications/
eclipse/plugins/
com.google.appengine.eclipse.sdkbundle_1.5.3.r37v201108301710/
appengine-java-sdk-1.5.3/lib/user/orm/datanucleus-
appengine-1.0.9.final.jar:/Applications/eclipse/plugins/
com.google.appengine.eclipse.sdkbundle_1.5.3.r37v201108301710/
appengine-java-sdk-1.5.3/lib/user/orm/datanucleus-core-1.1.5.jar:/
Applications/eclipse/plugins/
com.google.appengine.eclipse.sdkbundle_1.5.3.r37v201108301710/
appengine-java-sdk-1.5.3/lib/user/orm/datanucleus-jpa-1.1.5.jar:/
Applications/eclipse/plugins/
com.google.appengine.eclipse.sdkbundle_1.5.3.r37v201108301710/
appengine-java-sdk-1.5.3/lib/user/orm/geronimo-jpa_3.0_spec-1.1.1.jar:/
Applications/eclipse/plugins/
com.google.appengine.eclipse.sdkbundle_1.5.3.r37v201108301710/
appengine-java-sdk-1.5.3/lib/user/orm/geronimo-jta_1.1_spec-1.1.1.jar:/
Applications/eclipse/plugins/
com.google.appengine.eclipse.sdkbundle_1.5.3.r37v201108301710/
appengine-java-sdk-1.5.3/lib/user/orm/jdo2-api-2.3-eb.jar:/
Applications/eclipse/plugins/
com.google.appengine.eclipse.sdkbundle_1.5.3.r37v201108301710/
appengine-java-sdk-1.5.3/lib/appengine-tools-api.jar:/Users/Arkaaito/
Documents/AppEngine/scratch/surreality/war/WEB-INF/lib/google-api-java-
client-1.4.1-beta/dependencies/httpclient-4.0.3.jar:/Users/Arkaaito/
Documents/AppEngine/scratch/surreality/war/WEB-INF/lib/google-api-java-
client-1.4.1-beta/dependencies/httpcore-4.0.1.jar:/Users/Arkaaito/
Documents/AppEngine/scratch/surreality/war/WEB-INF/lib/google-api-java-
client-1.4.1-beta/google-api-client-1.4.1-beta.jar:/Users/Arkaaito/
Documents/AppEngine/scratch/surreality/war/WEB-INF/lib/google-api-java-
client-1.4.1-beta/google-api-client-googleapis-1.4.1-beta.jar:/Users/
Arkaaito/Documents/AppEngine/scratch/surreality/war/WEB-INF/lib/google-
api-java-client-1.4.1-beta/google-api-client-extensions-1.4.1-
beta.jar:/Users/Arkaaito/Documents/AppEngine/scratch/surreality/war/
WEB-INF/lib/google-api-java-client-1.4.1-beta/google-api-client-
googleapis-extensions-1.4.1-beta.jar:/Users/Arkaaito/Documents/
AppEngine/scratch/surreality/war/WEB-INF/lib/geronimo-
jpa_3.0_spec-1.1.1.jar:/Users/Arkaaito/Documents/AppEngine/scratch/
surreality/war/WEB-INF/lib/geronimo-jta_1.1_spec-1.1.1.jar
com.google.appengine.tools.development.DevAppServerMain --port=3333 /
Users/Arkaaito/Documents/AppEngine/scratch/surreality/war

Has anyone run into this problem before, or does anyone have suggestions on what we should do to debug? I'm sure it's something simple, probably a configuration problem, but as newbies we're not sure what to look at besides the classpaths.

4
  • Do you need to package some API jars in your web app? Commented Sep 18, 2011 at 22:58
  • The JARs are on the classpath - is there something else I need to do with them in order to have them packaged in as necessary? Commented Sep 18, 2011 at 23:01
  • The jars might need to be copied to your WEB-INF/lib folder. Are you using Maven, or did you just download the jars manually? Commented Sep 18, 2011 at 23:24
  • Downloaded them manually. Currently they're in ~/Documents/AppEngine/scratch/surreality/war/WEB-INF/lib/ - I've confirmed that for the JAR I think is relevant (google-api-client-1.4.1-beta.jar), the location in the generated command line matches up with the actual location of the file. Commented Sep 18, 2011 at 23:27

3 Answers 3

5

Within your WEB-INF/lib directory, you have some subdirectories google-api-java-client-1.4.1-beta and google-api-java-client-1.4.1-beta/dependencies with jars in those subdirectories that should be directly within WEB-INF/lib

Sign up to request clarification or add additional context in comments.

2 Comments

Ouch! Well, I did think the problem would be something painfully simple. I just didn't realize it was quite that painfully simple. Thanks!
@Arkaaito you appear to be confusing the configuration required to run the app engine, with the app engine running your app. The class path is to get the app engine running, and shouldn't need anything specific to your app. Setting up your application's access to all its dependencies is as for a standard servlet.
3

Do you have all of the dependencies in WEB-INF/lib ?

Comments

0

If you work with Google Cloud Engine and Eclipse:

Add jar files to a Appengine Project

  • It must be at Directory /{Base Directory}/src/main/webapp/WEB-INF/lib
  • Copy jar files to this directory
  • In Eclipse -> Project -> Build Path -> Configure Build Path -> Libraries -> Add External JARs: go to the /{Base Directory}/src/main/webapp/WEB-INF/lib and get the files

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.