4

我已将来自 aws-dynamodb-examples 的 DynamoDB 流适配器演示的代码合并到我的 Maven 项目中,但出现运行时错误:

Exception in thread "Thread-2" java.lang.NoClassDefFoundError: com/amazonaws/util/json/JSONObject
at com.amazonaws.services.kinesis.leases.impl.Lease.toString(Lease.java:229)

知道为什么会发生这种情况以及我能做些什么来解决它吗?

我的 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>com.aligntech</groupId>
  <artifactId>dynamodbstream</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>dynamodbstream</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      <maven.compiler.source>1.8</maven.compiler.source>
      <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

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

    <dependency>
      <groupId>com.amazonaws</groupId>
      <artifactId>dynamodb-streams-kinesis-adapter</artifactId>
      <version>LATEST</version>
    </dependency>


  </dependencies>
</project>
4

2 回答 2

9

如果我将版本更改aws-java-sdk1.10.77. 似乎 1.11.0 版中的 kinesis 库正在尝试使用已从com.amazonaws.util.json.

于 2016-05-16T14:56:21.387 回答
1

试试这个配置。对我有用,我认为这是正确的做法。使用此配置,您将与最新的 AWS 版本保持一致。

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "io.spring.gradle:dependency-management-plugin:1.0.0.RC2"
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: "io.spring.dependency-management"

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.7

repositories {
    mavenCentral()
    maven {
        url "http://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk"
    }

}

dependencyManagement {
    imports {
        mavenBom 'com.amazonaws:aws-java-sdk-bom:1.11.197'
    }
}

dependencies {

    compile group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.11.197'
    compile group: 'com.amazonaws', name: 'amazon-kinesis-client', version: '1.8.1'

    testCompile group: 'junit', name: 'junit', version: '4.12'
}
于 2017-09-19T21:31:18.970 回答