我正在为一个项目使用 google calendar java API。
日历部分没问题,maven 似乎可以轻松下载并使用它。
我的问题来自这个库的主要依赖项:com.google.api.client api。
特别是,当我按照 this page 中的详细说明进行操作时,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.jackson2 does not exist
它缺少几个类,因此无法编译文件,而当我下载 zip 并在不使用 maven 的情况下手动添加 .jar 时,它工作正常。
这是我用 maven 管理的第一个项目,不知道如何从那里开始。不胜感激。
编辑发布请求---这是我的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>
我基本上添加了两个依赖项:calendar 和 api client。这是让文档正常工作的提到的步骤。
最佳答案
似乎非常 beta-ish google-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>
此外,以下附加依赖项似乎是必需的:
<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-jackson2</artifactId>
<version>1.12.0-beta</version>
</dependency>
希望对您有所帮助。
关于java - google api的maven用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13662562/