gpt4 book ai didi

java - 使用 DropBox Core API 时出现 NoClassDefFoundError

转载 作者:行者123 更新时间:2023-11-30 02:30:46 25 4
gpt4 key购买 nike

我从官方 DropBox API 教程中复制粘贴了以下代码。此代码的目的是上传文本文件。我正在使用 DropBox-core-sdk-3.0.3.jar 。但我越来越

Exception in thread "main" java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/JsonParseException
at com.dropbox.core.DbxHost.<clinit>(DbxHost.java:114)
at com.dropbox.core.v2.DbxClientV2.<init>(DbxClientV2.java:31)
at dropboxtest.Main.main(Main.java:24)
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.core.JsonParseException
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)

现在解决这个问题的方法可能是将 jackson-annotations.jar 添加到类路径中,但是,我已经尝试过这个,这似乎不起作用,并且我得到了相同的异常,并且我有一些未使用的导入

这是代码:

package dropboxtest;

import com.dropbox.core.DbxException;
import com.dropbox.core.DbxRequestConfig;
import com.dropbox.core.v2.DbxClientV2;
import com.dropbox.core.v2.files.FileMetadata;
import com.dropbox.core.v2.files.ListFolderResult;
import com.dropbox.core.v2.files.Metadata;
import com.dropbox.core.v2.users.FullAccount;

import java.util.List;

import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;

public class Main {

private static final String ACCESS_TOKEN = "XXXXXX";

public static void main(String args[]) throws DbxException, IOException {
// Create Dropbox client
DbxRequestConfig config = new DbxRequestConfig("dropbox/java-tutorial", "en_US");
DbxClientV2 client = new DbxClientV2(config, ACCESS_TOKEN);

// Get current account info
FullAccount account = client.users().getCurrentAccount();
System.out.println(account.getName().getDisplayName());

// Get files and folder metadata from Dropbox root directory
ListFolderResult result = client.files().listFolder("");
while (true) {
for (Metadata metadata : result.getEntries()) {
System.out.println(metadata.getPathLower());
}

if (!result.getHasMore()) {
break;
}

result = client.files().listFolderContinue(result.getCursor());
}

// Upload "test.txt" to Dropbox
try (InputStream in = new FileInputStream("test.txt")) {
FileMetadata metadata = client.files().uploadBuilder("/test.txt")
.uploadAndFinish(in);
}
}
}

最佳答案

简短回答:使用jackson-core-x.x.x而不是jackson-annotation-xxx

长答案:正如 Gemini Keith 所指出的,问题出在我的类路径上。 dropbox-core-sdk-3.0.3.jar 实际上需要另一个库,它是 jackson-core-2.6.1。不过,DropBox 的 API v2 官方文档中没有提到这一点。但是在查看 DropBox 的 API v1 文档并阅读该行

The necessary JAR files are in the "lib/" folder.

我继续下载 API v1 示例代码。然后将 lib 文件夹中的 jackson-core-x.x.x 添加到我的当前类路径中,并且 VIOLA 一切正常。

关于java - 使用 DropBox Core API 时出现 NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44319563/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com