gpt4 book ai didi

java - 通过 Maven 导入的类出现 NoClassDef 错误

转载 作者:行者123 更新时间:2023-12-02 07:00:07 25 4
gpt4 key购买 nike

我在 Eclipse 中有一个通过 m2e 创建的 Maven 项目。它从 GitHub 上名为 alternator 的项目获取客户端库。在我的项目中,这些类似乎导入得很好,但在运行它们时,它显示 NoClassDefFound 错误。这是代码和错误:

代码:

public class Main{

private AlternatorDBClient client;
private DynamoDBMapper mapper;
private AlternatorDB db;

public static void main(String args[]) throws Exception{
new Main().run();
}

public void run() throws Exception {
this.client = new AlternatorDBClient();
this.mapper = new DynamoDBMapper(this.client);
this.db = new AlternatorDB().start();
}

}

错误:

Exception in thread "main" java.lang.NoClassDefFoundError: com/michelboudreau/alternator/AlternatorDBClient
at Main.run(Main.java:17)
at Main.main(Main.java:13)
Caused by: java.lang.ClassNotFoundException: com.michelboudreau.alternator.AlternatorDBClient
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more

最佳答案

AlternatorDBClient 类正在导入一个或多个不在类路径上的类:

import com.amazonaws.*;
import com.amazonaws.handlers.HandlerChainFactory;
import com.amazonaws.http.ExecutionContext;
import com.amazonaws.http.HttpResponseHandler;
import com.amazonaws.http.JsonErrorResponseHandler;
import com.amazonaws.http.JsonResponseHandler;
import com.amazonaws.services.dynamodb.AmazonDynamoDB;
import com.amazonaws.services.dynamodb.model.*;
import com.amazonaws.services.dynamodb.model.transform.*;
import com.amazonaws.transform.JsonErrorUnmarshaller;
import com.amazonaws.transform.JsonUnmarshallerContext;
import com.amazonaws.transform.Unmarshaller;
import com.amazonaws.util.json.JSONObject;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

你不知何故失踪了:

 <dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
</dependency>

作为项目 pom 中的依赖项。正如 AlexR 所说,请发布你的 pom。

关于java - 通过 Maven 导入的类出现 NoClassDef 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16758460/

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