java google api的Maven使用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13662562/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven usage of google api
提问by m09
I'm using the google calendar java API for a project.
我正在为一个项目使用谷歌日历 java API。
The calendar part is fine, maven seems to download it and use it without any hassle.
日历部分很好,maven 似乎下载并使用它没有任何麻烦。
My problem comes from the main dependency of this lib: the com.google.api.client api.
我的问题来自这个库的主要依赖项:com.google.api.client api。
In particular, when I follow the instructions detailed at this page, maven can't compile my project properly:
特别是,当我按照此页面上的详细说明进行操作时,maven 无法正确编译我的项目:
package com.google.api.client.extensions.java6.auth.oauth2 does not exist
package com.google.api.client.extensions.jetty.auth.oauth2 does not exist
package com.google.api.client.json.Hymanson2 does not exist
It lacks several classes and thus can't compile the file while when I download the zip and add the .jar manually without using maven it works fine.
它缺少几个类,因此无法编译文件,而当我下载 zip 并手动添加 .jar 而不使用 maven 时,它工作正常。
It's the first project I manage with maven and don't know how to go from there. Pointers would be appreciated.
这是我用 maven 管理的第一个项目,不知道如何从那里开始。指针将不胜感激。
edit post request --- here is my POM
编辑帖子请求 --- 这是我的 POM
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fr.univnantes.atal.atcal</groupId>
<artifactId>AtCal</artifactId>
<version>0.1</version>
<packaging>jar</packaging>
<name>AtCal</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>google-api-services</id>
<url>http://google-api-client-libraries.appspot.com/mavenrepo</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.12.0-beta</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-calendar</artifactId>
<version>v3-rev20-1.12.0-beta</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<!-- best lock down version of the plugin too -->
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
I basicly added two dependencies: calendar and api client. It was the mentionned step to get things working on the doc.
我基本上添加了两个依赖项:日历和 api 客户端。这是使文档工作的提到的步骤。
回答by Anders R. Bystrup
It seems that the seemingly verybeta-ish google-api-services-calendar:v3-rev20-1.12.0-beta
isn't pushed to the sontaype repository yet, but if you try to include both the recommended repo and the one mentioned under the Calendar API in your POM:
看起来似乎非常测试版的 ishgoogle-api-services-calendar:v3-rev20-1.12.0-beta
还没有推送到 Sontaype 存储库,但是如果您尝试在 POM 中同时包含推荐的存储库和日历 API 下提到的存储库:
<repositories>
<repository>
<id>google-api-services</id>
<url>https://oss.sonatype.org/content/repositories/releases/</url>
</repository>
<repository>
<id>google-api-services-beta</id>
<url>http://google-api-client-libraries.appspot.com/mavenrepo</url>
</repository>
</repositories>
Also, the following additional dependencies seem to be necessary:
此外,似乎还需要以下附加依赖项:
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client-java6</artifactId>
<version>1.12.0-beta</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client-jetty</artifactId>
<version>1.12.0-beta</version>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client-Hymanson2</artifactId>
<version>1.12.0-beta</version>
</dependency>
Hope that helps.
希望有帮助。
回答by Waldemar Wosiński
I had adventure with google custom search api. Most of the problem were due to unavailability of mvn repo http://google-api-client-libraries.appspot.com/mavenrepo.
我对 google 自定义搜索 api 进行了冒险。大多数问题是由于 mvn repo http://google-api-client-libraries.appspot.com/mavenrepo不可用。
Custom search jar I took from:
我从以下位置获取的自定义搜索 jar:
<repository>
<id>google-api-services</id>
<url>http://mavenrepo.google-api-java-client.googlecode.com/hg</url>
</repository>
It was in pom inside the jar downloaded manually. Newest google-api-clientand google-http-client-Hymanson(at 1.13.2-beta HymansonFactory is an additional dependency) were in central maven repo.
它在手动下载的 jar 中的 pom 中。最新的google-api-client和google-http-client-Hymanson(在 1.13.2-beta HymansonFactory 是一个额外的依赖项)在中央 maven 仓库中。
回答by user2407842
As of a few months ago, Google started pushing libraries to the Sonatype repo. You no longer should include a repository entry in your pom.xml pointing to google-api-client-libraries.appspot.com/mavenrepo
or mavenrepo.google-api-java-client.googlecode.com
几个月前,Google 开始将库推送到 Sonatype 存储库。您不再应该在 pom.xml 中包含指向google-api-client-libraries.appspot.com/mavenrepo
或mavenrepo.google-api-java-client.googlecode.com
Doing that slows down your builds because you end up checking for all dependencies (even non Google ones) at that repository. These checks 404, then you check the master repository.
这样做会减慢您的构建速度,因为您最终会检查该存储库中的所有依赖项(甚至非 Google 依赖项)。这些检查 404,然后您检查主存储库。