我如何获得com.google.common.base类。JavagDrive api的前提条件?

问题描述 投票:1回答:1

我正在按照快速入门教程尝试将Java接口与Google Drive API配合使用,但是每次运行程序时,它都会引发“ NoClassDefFoundError:com / google / common / base / Preconditions”。当我尝试实现Google CustomSearchEngine API时,也会发生这种情况。

我已经引用了所有带有或不带有源代码和javadocs的API类。我也曾尝试使用findJAR dot com来尝试获得前提条件,但收效甚微。

以下是错误所使用的代码行。在引用的代码上方的注释中,我还包括了定义错误行中使用的变量的行。

第61行:

/*
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();

InputStream in = new FileInputStream(clientSecretFilePath);
*/

GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));

第88行:

/*
final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
*/

Credential credential = getCredentials(HTTP_TRANSPORT);

错误:

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Preconditions
    at com.google.api.client.util.Preconditions.checkNotNull(Preconditions.java:127)
    at com.google.api.client.json.jackson2.JacksonFactory.createJsonParser(JacksonFactory.java:80)
    at com.google.api.client.json.JsonFactory.fromReader(JsonFactory.java:236)
    at com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets.load(GoogleClientSecrets.java:192)
    at drive.GDrive.getCredentials(GDrive.java:61)
    at drive.GDrive.main(GDrive.java:88)
Caused by: java.lang.ClassNotFoundException: com.google.common.base.Preconditions
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 6 more

看起来好像缺少一个类,但是我在构建配置中引用了Google Drive API中的所有API库。我什至尝试从findjar dot com获取缺少的类,但几乎没有其他进展。

java google-drive-api noclassdeffounderror
1个回答
0
投票
相同的问题:I can't find the dependency for com.google.api.client.util.Preconditions using Maven

似乎模块之间存在版本冲突google-api-client和google-http-client-jackson2。他们必须是相同的版本1.17.0-rc。
© www.soinside.com 2019 - 2024. All rights reserved.