1

This is the gradle dependencies. (UPDATED)

   compile group: 'net.sf.ehcache', name: 'ehcache', version: '2.10.4'
compile 'org.springframework:spring-context-support:4.3.8.RELEASE'
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.6'

compile group: 'com.google.api-client', name: 'google-api-client', version: '1.20.0'

this code generates the error.

   HttpTransport transport = new NetHttpTransport();
        JacksonFactory jsonFactory =
                new JacksonFactory();
        GoogleIdTokenVerifier verifier = new GoogleIdTokenVerifier.Builder(
                transport, jsonFactory)
                .setAudience(Collections.singletonList("1009293319809-dek5gcam0af2c52ute611c8p51cfvker.apps.googleusercontent.com"))
                // Or, if multiple clients access the backend:
                //.setAudience(Arrays.asList(CLIENT_ID_1, CLIENT_ID_2, CLIENT_ID_3))
                .build();

Received error

Caused by: java.lang.NoClassDefFoundError: com/google/api/client/json/JsonFactory
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethods(Class.java:1975)
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:613)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:524)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:510)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:247)
... 63 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.google.api.client.json.JsonFactory
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1892)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1735)
... 70 common frames omitted

enter image description here

Any idea of what library I am missing. I am assuming there is maybe conflict of libraries. how can I fix this?

1 Answer 1

1

Your screenshot shows 2 versions of the google-api-client library:

enter image description here

Also, you are importing the library twice in your gradle build file:

compile group: 'com.google.api.client', name: 'google-api-client', version: '1.4.1-beta'
...
compile group: 'com.google.api-client', name: 'google-api-client', version: '1.20.0'

The fact that you get java.lang.NoClassDefFoundError seems to be caused by the fact that the older version of the library does not contain the mentioned class and it is overriding the most recent version of the library. All you need to do is remove the reference to the older version of the library (1.4.1-beta) from your gradle file.

Sign up to request clarification or add additional context in comments.

13 Comments

I thought the class in question found in google-http-client-jackson
@Yohannes The tags are a little misleading. The error message clearly states the class not being found: Caused by: java.lang.NoClassDefFoundError: com/google/api/client/json/JsonFactory
@LouisBono I removed the beta but still it doesnt work. I put jackson tag because I am suspecting that can be also conflicting.
@legend12345 Are you getting the same error? Please post the details.
@LouisBono same as I wrote above. only now gradle has only 1.20.0 but still Caused by: java.lang.ClassNotFoundException: com.google.api.client.json.JsonFactory at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1892) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1735) ... 70 common frames omitted
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.