Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ShardRecordProcessorFactory - java.lang.NoClassDefFoundError #625

Closed
Wayne-II opened this issue Oct 15, 2019 · 2 comments
Closed

ShardRecordProcessorFactory - java.lang.NoClassDefFoundError #625

Wayne-II opened this issue Oct 15, 2019 · 2 comments

Comments

@Wayne-II
Copy link

Wayne-II commented Oct 15, 2019

I'm getting a stack trace while I try to run the package I built with Maven:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: software/amazon/kinesis/processor/ShardRecordProcessorFactory
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: software.amazon.kinesis.processor.ShardRecordProcessorFactory
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)
... 7 more

This is the result of setting up a Maven build environment and using the sample code provided for the Kinesis Client Library v2. Available here:
https://docs.aws.amazon.com/streams/latest/dev/kcl2-standard-consumer-java-example.html

I imagine there is a git repo of this code, but I haven't found it. I looked here: https://github.com/awslabs/amazon-kinesis-client/tree/master/amazon-kinesis-client/src/main/java/software/amazon/kinesis

Maven App Dependencies
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.9</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.28</version> </dependency> <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>sdk-core</artifactId> </dependency> <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>aws-core</artifactId> </dependency> <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>regions</artifactId> </dependency> <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>cloudwatch</artifactId> </dependency> <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>dynamodb</artifactId> </dependency> <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>kinesis</artifactId> </dependency> <dependency> <groupId>software.amazon.kinesis</groupId> <artifactId>amazon-kinesis-client</artifactId> <version>2.2.4</version> </dependency>

Dependency management
<dependencyManagement> <dependencies> <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>bom</artifactId> <version>2.5.10</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>

I'm using:
KCL 2.2.4
AWS-SDK 2.9.20 - ( tried 2.9.19, 2.9.10, 2.8.7, 2.5.10 )
Java 1.8.0_45
JRE 1.8.0_45-b14

AWS-SDK 2.9.[19, 10] and 2.8.7 were shots in the dark.

I have read the following issues and have not been able to come up with a solution that would work for me: #266 #323 #577 #485

I tried AWS-SDK 2.5.10 due to the POM file referenced: #350 (comment)
This POM file used AWS-SDK 2.5.10 with KCL 2.2.4.

However, I did not understand what this follow up comment meant: #350 (comment)

#485 #323 and #577 seemed irrelevant

I've tried almost nothing and I'm all out of ideas.

Googling has been less helpful for ideas than the issue search. However, I did come across someone getting a dependency issue for a Google lib. I cannot find it and I am not 100% certain they were using AWS-SDK and KCL, but I think they were. I am mistaking that SO that I cannot find with the one referenced below where they were using older 1.x versions and changing SDK version solved their issue. This is what I would chase next, but I haven't the slightest where to start.

However my shots in the dark were inspired by the following SO: https://stackoverflow.com/questions/37734500/aws-kinesis-client-fails-with-java-lang-noclassdeffounderror
I tried finding which AWS-SDKs were supported by KCL and came up empty. Thus the shots in the dark.

@Wayne-II
Copy link
Author

This is what I would chase next, but I haven't the slightest where to start.

Adding the classpath for the maven repo libs individually solved the issue:
-cp /Users/wayne/workspace/project-dev/maven-project/target/project-1.0-SNAPSHOT.jar:/Users/wayne/.m2/repository/software/amazon/kinesis/amazon-kinesis-client/2.2.4/amazon-kinesis-client-2.2.4.jar

@Wayne-II
Copy link
Author

A better solution was the following Maven configurations:

<artifactId>maven-resources-plugin</artifactId> <executions> <execution> <id>copy-resources</id> <phase>validate</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${basedir}/target/</outputDirectory> <resources> <resource> <directory>resources</directory> <filtering>true</filtering> </resource> </resources> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>prepare-package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/lib</outputDirectory> <overWriteIfNewer>true</overWriteIfNewer> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <mainClass>fully.qualified.mainClass</mainClass> </manifest> <manifestEntries> <Class-Path>.</Class-Path> </manifestEntries> </archive> </configuration> </plugin>

Sorry, I don't know how to paste code os it will format properly.

I stole and modified this from: https://crunchify.com/how-to-create-build-java-project-including-all-dependencies-using-maven-maven-resources-maven-dependency-maven-jar-plugin-tutorial/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant