我想在java控制台应用程序中使用google-api-services-plus-v1 lib,但每当执行以下代码时,我都会收到ClassDefFoundError:
Plus.Activities.Search req = service.activities().search(q);
ActivityFeed feed = req.execute();
例外:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/appengine/api/urlfetch/HTTPMethod
at com.google.api.client.extensions.appengine.http.UrlFetchTransport.buildRequest(UrlFetchTransport.java:125)
如何添加这些库?
答案 0 :(得分:2)
您正在使用AppEngine的google-api-java-client发行版:
以下是Servlet应用程序所需的依赖项文件夹中的jar(或每个依赖项的较新兼容版本):
google-api-client-1.17.0-rc.jar
google-api-client-servlet-1.17.0-rc.jar
google-oauth-client-1.17.0-rc.jar
google-oauth-client-servlet-1.17.0-rc.jar
google-http-client-1.17.0-rc.jar
commons-logging-1.1.1.jar
gson-2.1.jar
httpclient-4.0.3.jar
httpcore-4.0.1.jar
jackson-core-asl-1.9.4.jar
jackson-core-2.1.3.jar
jdo2-api-2.3-eb.jar
jsr305-1.3.9.jar
protobuf-java-2.2.0.jar
transaction-api-1.1.jar
xpp3-1.1.4c.jar
用于一般用途(命令行):
google-api-client-1.17.0-rc.jar
google-oauth-client-1.17.0-rc.jar
google-http-client-1.17.0-rc.jar
commons-logging-1.1.1.jar
gson-2.1.jar
httpclient-4.0.3.jar
httpcore-4.0.1.jar
jackson-core-asl-1.9.4.jar
jackson-core-2.1.3.jar
jsr305-1.3.9.jar
protobuf-java-2.2.0.jar
xpp3-1.1.4c.jar
请看一下如何选择正确的库:
https://code.google.com/p/google-api-java-client/wiki/Setup
如果您正在使用maven并且您的软件必须在servlet容器中运行,请尝试以下依赖项:
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client-servlet</artifactId>
<version>1.17.0-rc</version>
</dependency>
而不是
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client-appengine</artifactId>
<version>1.17.0-rc</version>
</dependency>