practicemakesperfect
practicemakesperfect

Reputation: 387

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.

Upvotes: 3

Views: 10326

Answers (2)

amdg
amdg

Reputation: 2239

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

Upvotes: 1

Matthias J. Sax
Matthias J. Sax

Reputation: 62350

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.

Upvotes: 1

Related Questions