4

I've incorporated the code from DynamoDB streams adapter demo from aws-dynamodb-examples, into my Maven project, and I'm getting a run-time error:

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)

Any idea why this happens and what I can do to fix it?

My pom file is this:

<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>
Siguza
  • 21,155
  • 6
  • 52
  • 89
Adi Levin
  • 5,165
  • 1
  • 17
  • 26

2 Answers2

9

The problem is resolved if I change the version of aws-java-sdk to 1.10.77. It seems that the kinesis library in version 1.11.0 is trying to use JSONObject which has been removed from com.amazonaws.util.json.

Adi Levin
  • 5,165
  • 1
  • 17
  • 26
  • The aws-java-sdk is currently at 2.0 and I am having this problem still. What version should I be at now to stop having this issue? – Dan Csharpster Apr 28 '18 at 19:32
1

Try this configuration. Works for me and I think this is the correct way of doing it. With this configuration you are aligned with latest AWS versions.

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'
}
user3734429
  • 322
  • 1
  • 10