我和一个朋友正在使用Java SDK涉足App Engine。我们成功地编写了一个“Hello, World”示例,但是当我们尝试添加代码并使用com.google.api.client.http中的类来调用一个简单的Web服务时,代码可以编译通过,但会引起运行时错误:
需要翻译的内容:
我们最好的猜测是构建类路径和运行时类路径之间存在差异,但我们的运行时类路径似乎没问题。 HttpTransport类在google-api-client-1.4.1-beta.jar库中,这个库被包含在Eclipse命令行生成要运行该项目的命令中。
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)
需要翻译的内容:
涉及代码如下:
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;
}
}
}
我们最好的猜测是构建类路径和运行时类路径之间存在差异,但我们的运行时类路径似乎没问题。 HttpTransport类在google-api-client-1.4.1-beta.jar库中,这个库被包含在Eclipse命令行生成要运行该项目的命令中。
/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
有没有人遇到过这个问题,或者有没有建议我们应该如何进行调试?我相信这是一个简单的问题,可能是一个配置问题,但作为新手,除了查看类路径之外,我们不确定应该查看什么。