简体   繁体   中英

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. 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:

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.

I just fixed this by changing the following lines:

Original: import com.google.api.client.json.jackson.JacksonFactory;

Modified: 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.

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

Do you have them all? It sounds like you have #2, but it sounds like you're missing the google HTTP client .

  1. In POM add below dependency-

     <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

    import com.google.api.client.json.JsonFactory;
    import com.google.api.client.json.gson.GsonFactory;
  1. Usage

     private static final JsonFactory JSON_FACTORY = GsonFactory.getDefaultInstance(); GoogleClientSecrets clientSecrets =GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM