[英]java.lang.ClassNotFoundException: com.google.api.client.json.JsonFactory
I want to create a web application running on Tomcat 7.0 with JRE JavaSE-1.6 on osx 10.8.我想创建一个在 Tomcat 7.0 上运行的 web 应用程序,在 osx 10.8 上使用 JRE JavaSE-1.6。 I am using a tutorial from the developers site and the error occurs when I try to call我正在使用来自开发者网站的教程,当我尝试调用时出现错误
clientSecrets = GoogleClientSecrets.load(new JacksonFactory(), reader);
I added the Jar google-http-client-jackson-1.16.0-rc.jar to my build path and still get following error:我将 Jar google-http-client-jackson-1.16.0-rc.jar 添加到我的构建路径中,但仍然出现以下错误:
java.lang.NoClassDefFoundError: com/google/api/client/json/JsonFactory
java.lang.ClassNotFoundException: com.google.api.client.json.JsonFactory
My classpath specifically points to this Jar too.我的类路径也特别指向这个 Jar。
I just fixed this by changing the following lines:我只是通过更改以下行来解决此问题:
Original: import com.google.api.client.json.jackson.JacksonFactory;
原文: import com.google.api.client.json.jackson.JacksonFactory;
Modified: import com.google.api.client.json.jackson2.JacksonFactory;
修改: import com.google.api.client.json.jackson2.JacksonFactory;
I had a similar problem and solved it by manually adding the required JAR's to my WEB-INF\lib folder outside Eclipse.我遇到了类似的问题,并通过手动将所需的 JAR 添加到 Eclipse 之外的我的 WEB-INF\lib 文件夹中解决了这个问题。
From this page here , it says you need 3 libraries: 1) The Generated Java client library for BigQuery 2) The Google HTTP Client Library for Java 3) The Google OAuth Client Library for Java在此页面上,它说您需要 3 个库:1) BigQuery 生成的 Java 客户端库 2) Java 的 Google HTTP 客户端库 3) Java 的 Google OAuth 客户端库
Do you have them all?你都有吗? It sounds like you have #2, but it sounds like you're missing the google HTTP client .听起来您有 #2,但听起来您缺少 google HTTP client 。
In POM add below dependency-在 POM 中添加以下依赖项-
<dependency> <groupId>com.google.api-client</groupId> <artifactId>google-api-client-gson</artifactId> <version>2.1.1</version> </dependency> <dependency> <groupId>com.google.oauth-client</groupId> <artifactId>google-oauth-client-jetty</artifactId> <version>1.34.1</version> </dependency>
Note: In above dependency version can be changed注意:在上面的依赖版本中可以更改
2.Import statement 2.导入声明
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;
Usage用法
private static final JsonFactory JSON_FACTORY = GsonFactory.getDefaultInstance(); GoogleClientSecrets clientSecrets =GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.