java Kafka Utils 错误的类路径:org.apache.kafka.common.utils.Utils

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28353316/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 13:25:50  来源:igfitidea点击:

Kafka Utils wrong classpath: org.apache.kafka.common.utils.Utils

javaapache-kafka

提问by joshft91

I'm attempting to make a very simple Kafka Producer and am currently following the producer exampleexcept my producer does not have a partitioner class.

我正在尝试制作一个非常简单的 Kafka Producer,并且目前正在关注生产者示例,但我的生产者没有分区器类。

After exporting required files into a jar I transfer them to my Linux image and try to run it.

将所需文件导出到 jar 后,我将它们传输到我的 Linux 映像并尝试运行它。

I get this exception:

我得到这个例外:

Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.NoClassDefFoundError: org/apache/kafka/common/utils/Utils
    at kafka.client.ClientUtils$$anonfun$parseBrokerList.apply(ClientUtils.scala:103)
    at kafka.client.ClientUtils$$anonfun$parseBrokerList.apply(ClientUtils.scala:102)
    at scala.collection.TraversableLike$$anonfun$map.apply(TraversableLike.scala:194)
    at scala.collection.TraversableLike$$anonfun$map.apply(TraversableLike.scala:194)
    at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:60)
    at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:44)
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:194)
    at scala.collection.mutable.ArrayBuffer.map(ArrayBuffer.scala:44)
    at kafka.client.ClientUtils$.parseBrokerList(ClientUtils.scala:102)
    at kafka.producer.BrokerPartitionInfo.<init>(BrokerPartitionInfo.scala:32)
    at kafka.producer.async.DefaultEventHandler.<init>(DefaultEventHandler.scala:41)
    at kafka.producer.Producer.<init>(Producer.scala:60)
    at kafka.javaapi.producer.Producer.<init>(Producer.scala:26)
    at producers.HelloWorldProducer.main(HelloWorldProducer.java:20)
    ... 5 more
Caused by: java.lang.ClassNotFoundException: org.apache.kafka.common.utils.Utils
    at java.net.URLClassLoader.run(URLClassLoader.java:366)
    at java.net.URLClassLoader.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 19 more

After looking at the kafka jar I see that the utilsis its own package now and not located within common.

查看 kafka jar 后,我发现utils它现在是它自己的包,而不是位于common.

What would be the best way to solve this issue?

解决此问题的最佳方法是什么?

回答by joshft91

The answer ended up being real silly ... I needed to use the kafka-clients-0.8.2.0.jarinstead.

答案最终变得非常愚蠢......我需要kafka-clients-0.8.2.0.jar改用 。