AWS Kinesis 客户端失败 java.lang.NoClassDefFoundError

AWS Kinesis client fails with java.lang.NoClassDefFoundError

我正在关注 Kinesis Streams 上的 http://docs.aws.amazon.com/streams/latest/dev/learning-kinesis-module-one.html 教程。

我创建了两个包,一个包含生产者,一个包含消费者。我可以正确地生成数据,并且可以从指标仪表板中看到数据正在进入流中。

当我 运行 我的消费者时,我得到以下堆栈跟踪:

1246 [main] DEBUG com.amazonaws.services.kinesis.samples.stocktrades.processor.StockTradesProcessor  - Caught throwable while processing data.
java.lang.NoClassDefFoundError: com/amazonaws/util/json/JSONObject
at com.amazonaws.services.kinesis.leases.impl.Lease.toString(Lease.java:229)
at java.lang.String.valueOf(Unknown Source)
at java.lang.StringBuilder.append(Unknown Source)
at com.amazonaws.services.kinesis.leases.impl.LeaseManager.createLeaseIfNotExists(LeaseManager.java:281)
at com.amazonaws.services.kinesis.clientlibrary.lib.worker.ShardSyncer.syncShardLeases(ShardSyncer.java:127)
at com.amazonaws.services.kinesis.clientlibrary.lib.worker.ShardSyncer.checkAndCreateLeasesForNewShards(ShardSyncer.java:88)
at com.amazonaws.services.kinesis.clientlibrary.lib.worker.ShardSyncTask.call(ShardSyncTask.java:68)
at com.amazonaws.services.kinesis.clientlibrary.lib.worker.MetricsCollectingTaskDecorator.call(MetricsCollectingTaskDecorator.java:49)
at com.amazonaws.services.kinesis.clientlibrary.lib.worker.Worker.initialize(Worker.java:395)
at com.amazonaws.services.kinesis.clientlibrary.lib.worker.Worker.run(Worker.java:330)
at com.amazonaws.services.kinesis.samples.stocktrades.processor.StockTradesProcessor.main(StockTradesProcessor.java:102)
Caused by: java.lang.ClassNotFoundException: com.amazonaws.util.json.JSONObject
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 11 more

我刚遇到同样的问题。 把aws-sdk的版本改成1.10.x就可以了。我用的是 1.10.7 可能是您使用的是 aws-sdk 版本 1。11.x

Kinesis 客户端库 (KCL) 与 AWS Java SDK 1.11 不兼容。你需要使用 1.10.x.

这已在 KCL 1.6.4 中修复。因此,您可以更新 KCL(> 1.6.4)以使用 SDK 1。11.x https://github.com/awslabs/amazon-kinesis-client/pull/75