0

I am trying to get a clean code sample of Google API OAuth2 authentication. My code is mostly based on the explanation at https://code.google.com/p/google-api-java-client/wiki/OAuth2

I deviate from this tutorial because I want my libraries be managed by Maven and because I want to create a project without Google Apps Engine dependencies.

Each time I try to the run the project on my Glassfish server, I get the following error, probably indicating a dependency conflict.

java.lang.NoSuchMethodError: com.google.api.client.json.JsonFactory.fromInputStream(Ljava/io/InputStream;Ljava/lang/Class;)Ljava/lang/Object;

The relevant piece of my pom.xml:

<dependencies> <dependency> <groupId>com.google.api-client</groupId> <artifactId>google-api-client</artifactId> <version>1.14.1-beta</version> </dependency> <dependency> <groupId>com.google.http-client</groupId> <artifactId>google-http-client</artifactId> <version>1.14.1-beta</version> </dependency> <dependency> <groupId>com.google.api-jackson2</groupId> <artifactId>google-api-jackson2</artifactId> <version>1.14.1-beta</version> </dependency> <dependency> <groupId>com.google.apis</groupId> <artifactId>google-api-services-calendar</artifactId> <version>v3-rev34-1.14.1-beta</version> </dependency> <dependency> <groupId>com.google.oauth-client</groupId> <artifactId>google-oauth-client</artifactId> <version>1.14.1-beta</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.1.3</version> </dependency> <dependency> <groupId>com.google.oauth-client</groupId> <artifactId>google-oauth-client-servlet</artifactId> <version>1.14.1-beta</version> </dependency> <dependency> <groupId>javax.persistence</groupId> <artifactId>persistence-api</artifactId> <version>1.0.2</version> </dependency> <dependency> <groupId>javax.validation</groupId> <artifactId>validation-api</artifactId> <version>1.1.0.CR2</version> </dependency> <dependency> <groupId>javax.faces</groupId> <artifactId>jsf-api</artifactId> <version>2.1</version> </dependency> <dependency> <groupId>javax.enterprise</groupId> <artifactId>cdi-api</artifactId> <version>1.1-PRD</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.0.1</version> </dependency> <dependency> <groupId>javax.annotation</groupId> <artifactId>jsr250-api</artifactId> <version>1.0</version> </dependency> <dependency> <groupId>javax</groupId> <artifactId>javaee-web-api</artifactId> <version>6.0</version> </dependency> </dependencies> 

Please help me find the root cause of this error, because the used dependencies seem just fine to me and there's no similar problem case I could find.

4
  • Seems to me that there is a library referencing to a another library and its expecting to have that method, the issue most of the time is because one of the libraries is not the correct version in front of the second library. Commented Mar 28, 2013 at 13:40
  • @Garis, this seems exactly the problem, but as shown in the maven pom file, all the google related api's seem the most recent and corresponding version (1.14.1-beta) Commented Mar 28, 2013 at 13:44
  • you sure are the libraries are being downloaded? Commented Mar 28, 2013 at 13:46
  • @Garis: All jars are downloaded successfully by maven, except for "google-http-client-jackson-1.14.1-beta.jar". This jar I extracted from the google OAuth example project at the link in the OP, and added it to Maven with a manual 'maven install-file'. Commented Mar 28, 2013 at 13:53

1 Answer 1

1

The correct dependency for jackson2 is:

<dependency> <groupId>com.google.http-client</groupId> <artifactId>google-http-client-jackson2</artifactId> <version>1.14.1-beta</version> </dependency> 

Once I changed that, the project built successfully, and I was able to call the method in question just fine.

There could be something else on the classpath that's interfering. I suggest you run the program with -verbose: class (see here for a more detailed explanation), which will show any conflicts.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.