线程“主”中的异常java.lang.NoClassDefFoundError:com / amazonaws / endpointdiscovery / EndpointDiscoveryProviderChain

时间:2018-11-27 21:02:52

标签: java amazon-web-services amazon-dynamodb noclassdeffounderror

我正在研究一种工具,该工具将从dynamoDB中提取数据并遵循this tutorial中的步骤
所以我有以下代码:

package dynamodbtocsvfile;

import java.util.Map;

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import com.amazonaws.services.dynamodbv2.model.ScanRequest;
import com.amazonaws.services.dynamodbv2.model.ScanResult;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;

public class dynamoDbScan {

    public dynamoDbScan() {}

    public static void main(String[] args) {
        AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().build();

        ScanRequest scanRequest = new ScanRequest()
            .withTableName("Reply");

        ScanResult result = client.scan(scanRequest);
        for (Map<String, AttributeValue> item : result.getItems()){
            System.out.println(item);
        }
    }

}

这是我的pom.xml依赖项:

<dependencies>

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-csv</artifactId>
    <version>1.1</version>
</dependency>
<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk-core</artifactId>
    <version>1.11.24</version>
</dependency>
<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk-dynamodb</artifactId>
    <version>1.11.456</version>
</dependency>

文件生成没有错误,但是,当我运行它时,出现以下错误:

    Exception in thread "main" java.lang.NoClassDefFoundError: com/amazonaws/endpointdiscovery/EndpointDiscoveryProviderChain
    at dynamodbtocsv4j.dynamoDbScan.main(dynamoDbScan.java:16)
Caused by: java.lang.ClassNotFoundException: com.amazonaws.endpointdiscovery.EndpointDiscoveryProviderChain
    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)
    ... 1 more

这是我的.classpath文件内容:

 <?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" output="target/classes" path="main/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" output="target/test-classes" path="src/test/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="C:/Users/USERNAME/.m2/repository/com/amazonaws/aws-java-sdk-dynamodb/1.11.456/aws-java-sdk-dynamodb-1.11.456.jar" sourcepath="C:/Users/USERNAME/.m2/repository/com/amazonaws/aws-java-sdk-dynamodb/1.11.456/aws-java-sdk-dynamodb-1.11.456-sources.jar">
        <attributes>
            <attribute name="javadoc_location" value="jar:file:/C:/Users/USERNAME/.m2/repository/com/amazonaws/aws-java-sdk-dynamodb/1.11.456/aws-java-sdk-dynamodb-1.11.456-javadoc.jar!/"/>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="org.eclipse.jst.component.nondependency" value=""/>
            <attribute name="maven.groupId" value="com.amazonaws"/>
            <attribute name="maven.artifactId" value="aws-java-sdk-dynamodb"/>
            <attribute name="maven.version" value="1.11.456"/>
            <attribute name="maven.scope" value="compile"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="C:/Users/USERNAME/.m2/repository/com/amazonaws/aws-java-sdk-core/1.11.24/aws-java-sdk-core-1.11.24.jar" sourcepath="C:/Users/USERNAME/.m2/repository/com/amazonaws/aws-java-sdk-core/1.11.24/aws-java-sdk-core-1.11.24-sources.jar">
        <attributes>
            <attribute name="javadoc_location" value="jar:file:/C:/Users/USERNAME/.m2/repository/com/amazonaws/aws-java-sdk-core/1.11.24/aws-java-sdk-core-1.11.24-javadoc.jar!/"/>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="maven.groupId" value="com.amazonaws"/>
            <attribute name="maven.artifactId" value="aws-java-sdk-core"/>
            <attribute name="maven.version" value="1.11.24"/>
            <attribute name="maven.scope" value="compile"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="C:/Users/USERNAME/.m2/repository/org/apache/commons/commons-csv/1.1/commons-csv-1.1.jar"/>
    <classpathentry kind="lib" path="C:/Users/USERNAME/.m2/repository/com/amazonaws/jmespath-java/1.11.66/jmespath-java-1.11.66.jar"/>
    <classpathentry kind="output" path="target/classes"/>
</classpath>

非常感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

您是否尝试过在同一版本中使用所有SDK依赖性,例如1.11.457?

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk-core</artifactId>
    <version>1.11.457</version>
</dependency>
<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk-dynamodb</artifactId>
    <version>1.11.457</version>
</dependency>