Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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

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$1.apply(ClientUtils.scala:103)
    at kafka.client.ClientUtils$$anonfun$parseBrokerList$1.apply(ClientUtils.scala:102)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:194)
    at scala.collection.TraversableLike$$anonfun$map$1.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$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.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 utils is its own package now and not located within common.

What would be the best way to solve this issue?

like image 820
joshft91 Avatar asked Jan 08 '23 23:01

joshft91


1 Answers

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

like image 173
joshft91 Avatar answered Jan 31 '23 08:01

joshft91