Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kafka-run-class error could not find or load main class

https://kafka.apache.org/10/documentation/streams/quickstart

I'm trying to run my own application (on Linux) using Kafka Streams. I was able to successfully follow the instructions on their page and run the WordCountDemo application. Now I'm trying to use my own app (right now it is the same code, but I plan on doing something else with it) and when I write the command bin/kafka-run-class.sh com.zzz.WordCount I get Error: Could not find or load main class com.zzz.WordCount

I have my own WordCount.java like the following

/opt/kafka_2.12-1.0.0/src/main/com/zzz/WordCount.java

Is there anything else I need to do with my own app in order to be able to run it with kafka streams on my machine? Thanks.

like image 801
practicemakesperfect Avatar asked Nov 28 '25 19:11

practicemakesperfect


2 Answers

You need to make sure that bin/kafka-run-class.sh finds your own class in the Java classpath.

Before you run bin/kafka-run-class.sh execute

export CLASSPATH="$CLASSPATH":"/opt/kafka_2.12-1.0.0/src/main/"

This should allow bin/kafka-run-class.sh to pick it up correctly.

like image 99
Matthias J. Sax Avatar answered Nov 30 '25 07:11

Matthias J. Sax


I created the maven project containing the WordCountDemo.java program on my local machine. Executed the following steps

  • Export the project as a jar file - e.g. WordCount.jar.
  • Put the jar file on some server with the kafka setup.
  • Specify that jar file in the classpath.

export CLASSPATH="$CLASSPATH":"/my/sever/dir/WordCount.jar"

Then the following command was executed without any problem.

bin/kafka-run-class.sh com.zzz.WordCountDemo
like image 27
amdg Avatar answered Nov 30 '25 07:11

amdg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!