简体   繁体   中英

kafka producer example - class not found exception

I'm trying to run the kafka producer example as described on the kafka docs ( found here ).

However, when I try to run the producer I get a class not found exception:

Exception in thread "main" java.lang.NoClassDefFoundError: kafka/producer/ProducerConfig at com.t4g.app.RandomProducer.main(TestProducer.java:20) Caused by: java.lang.ClassNotFoundException: kafka.producer.ProducerConfig

Here is my dependency file:

<dependency>
  <groupId>org.apache.kafka</groupId>
  <artifactId>kafka_2.9.2</artifactId>
  <version>0.8.1.1</version>
  <scope>compile</scope>
  <exclusions>
    <exclusion>
      <artifactId>jmxri</artifactId>
      <groupId>com.sun.jmx</groupId>
    </exclusion>
    <exclusion>
      <artifactId>jms</artifactId>
      <groupId>javax.jms</groupId>
    </exclusion>
    <exclusion>
      <artifactId>jmxtools</artifactId>
      <groupId>com.sun.jdmk</groupId>
    </exclusion>
  </exclusions>
</dependency>

I am able to run the code using your pom.xml. Are you able to see ProducerConfig class in Maven dependencies?

Try a clean build or delete the existing Kafka package [kafka_2.9.2-0.8.1.1.jar] from Maven repository, update project to download the package again and see if it works for you.

在此处输入图片说明

Add the following in your pom.xml. It will fix your issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM