0

I'm currently working on setting up an tomcat8-server and want to write an servlet on it, which handles POST-requests with sensorvalues attached to it.

I want this sensordata to be emitted to Apache Kafka through a producer, setted up in the servlet. I wanted to set up a test-http-servlet with the code from "How to send a message via Kafka.Producer from a java servlet to Kafka" to learn writing my own.

But on compiling with:javac -cp /home/tobias/apache-tomcat-8.5.8/lib/servlet-api.jar HTTPServlet.java

, I get the following message:

HTTPServlet.java:19: error: package kafka.producer does not exist import kafka.producer.ProducerConfig; ^ HTTPServlet.java:20: error: package kafka.javaapi.producer does not exist import kafka.javaapi.producer.ProducerData; ^

I did already put the "kafka_2.11-0.10.1.0.jar", which contains the "kafka.producer.ProducerConfig"-class into the "WEB-INF/lib" folder, but It does not seem to work.

This "kafka_2.11-0.10.1.0.jar" was located in the "libs" folder of "kafka_2.11-0.10.1.0", which can be downloaded from the kafka-website.

So I wanted to ask, how I would get this working and If anyone knows, where the 2. missing file is located in the latest release of kafka.

Community
  • 1
  • 1
  • You need to put all those jars in the command line -cp option just like you did with servlet-api.jar – Strelok Nov 30 '16 at 10:19
  • 1
    You should start using an IDE rather than attempting to compile something less trivial than a "hello, world" app on the command line. – Strelok Nov 30 '16 at 10:20
  • Thank you very much!! Do you also know where the "ProducerData"-class went in the new release of kafka? – Tobias Gent Nov 30 '16 at 10:47

1 Answers1

0

I solved the problem (thanks to Strelok) by adding the additional api.jar-files to my compile-command:javac -cp /home/tobias/apache-tomcat-8.5.8/lib/servlet-api.jar:/home/tobias /apache-tomcat-8.5.8/webapps/HTTPServlet/WEB-INF/lib/kafka_2.11-0.10.1.0.jar HTTPServlet.java

The import for the ProducerData: import kafka.javaapi.producer.ProducerData; is not possible anymore, because the ProducerData.class was removed from the 0.6 to 0.7 release of kafka. I recommend using the ProducerRecord.class (worked for my test-example).