我和朋友正在使用Java SDK在App Engine中進行遊戲。我們有 彙總了一個「你好,世界」的例子,沒有問題;然而,當我們 嘗試添加代碼com.google.api.client.http使用 類,可以到WebService一個簡單的通話,我們的代碼編譯罰款,但 導致運行時錯誤:使用Google App Engine for Java的ClassNotFoundException
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類是在谷歌的API客戶端-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
有沒有人遇到這個問題之前還是沒有人有我們應該做的調試 建議?我確定這很簡單,可能是一個配置問題,但作爲新手,我們不知道除了classpath之外還需要看什麼。
直接您需要打包在你的web應用中的一些API罐子? –
JAR位於類路徑中 - 是否還有其他需要我們處理的內容,以便根據需要打包它們? – Arkaaito
可能需要將jar文件複製到WEB-INF/lib文件夾中。你在使用Maven,還是隻是手動下載了罐子? –