Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting NoClassDefFoundError on JSONObject in amazon-kinesis-client?

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>
like image 532
Adi Levin Avatar asked Dec 25 '22 05:12

Adi Levin


2 Answers

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.

like image 147
Adi Levin Avatar answered Jan 24 '23 14:01

Adi Levin


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'
}
like image 25
user3734429 Avatar answered Jan 24 '23 15:01

user3734429