我正在使用intellij idea开发下面这个简单的java应用程序。当我从ide执行它时,它就工作了。但是如果我从linux终端编译并执行,我会得到:
# javac -classpath kafka-clients-1.1.0.jar prova.java
# java prova -classpath kafka-clients-1.1.0.jar
Error: mpossible to initialize the main test class
Caused by: java.lang.NoClassDefFoundError: org/apache/kafka/clients/producer/Callback
import java.util.Properties;
import org.apache.kafka.clients.producer.Callback;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.RecordMetadata;
public class prova {
public static void main(String[] args) {
System.out.println("start");
Properties properties = new Properties();
properties.setProperty("bootstrap.servers", "127.0.0.1:9092");
properties.setProperty("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
properties.setProperty("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
// Crea producer:
KafkaProducer<String, String> producer = new KafkaProducer<String, String>(properties);
try
{
producer.send(new ProducerRecord<String, String>("topicthreepart", "chiave4" , "buonasera" ), new Callback() {
public void onCompletion(RecordMetadata metadata, Exception e) {
if (e != null) {
System.out.println("wrong");
} else {
System.out.println("correct");
System.out.println("timestamp: "+ metadata.timestamp());
System.out.println("topic: "+ metadata.topic());
System.out.println("offset: "+ metadata.offset());
System.out.println("partition: "+ metadata.partition());
}
}
}).get();
}
catch (Exception ex)
{
System.out.print(ex.getMessage());
}
}
}
暂无答案!
目前还没有任何答案,快来回答吧!