[error] /root/kafka-sbt/file.java:5:1: class SimpleProducer is public, should be declared in a file named SimpleProducer.java

0 votes

Hi,

Can anyone tell me why I am getting error when running the below command.

$ sbt compile

[error] /root/kafka-sbt/file.java:5:1: class SimpleProducer is public, should be declared in a file named SimpleProducer.java
[error] public class SimpleProducer {
[error]
[error]     public static void main(String[] args) throws Exception {
[error]
[error]         String topicName = "SimpleProducerTopic";
[error]         String key = "Key1";
[error]         String value = "Value-1";
[error]
[error]         Properties props = new Properties();
[error]         props.put("bootstrap.servers", "localhost:9092,localhost:9093");
[error]         props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
[error]         props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
[error]
[error]         Producer<String, String> producer = new KafkaProducer<>(props);
[error]
[error]         ProducerRecord<String, String> record = new ProducerRecord<>(topicName, key, value);
[error]         producer.send(record);
[error]         producer.close();
[error]
[error]         System.out.println("SimpleProducer Completed.");
[error]     }
[error] }
[error] (Compile / compileIncremental) javac returned non-zero exit code
[error] Total time: 30 s, completed Feb 10, 2020 11:56:36 AM

Feb 10 in Apache Kafka by akhtar
• 10,150 points
59 views

1 answer to this question.

0 votes

Hi@akhtar,

This error is not related to sbt. Actually this error occurs because you did not named your file name as class name. Change your file name or class name and try once again.

Thank You

answered Feb 10 by MD
• 22,020 points

Related Questions In Apache Kafka

0 votes
1 answer

Is there any change in consumer offsets if a new partition(s) is added to a Kafka topic?

Yes, it stays the same. An offset is ...READ MORE

answered Jul 9, 2018 in Apache Kafka by nitinrawat895
• 10,920 points
574 views
0 votes
1 answer

How to delete a topic in Kafka 0.8.1.1?

Deleting topic isn't always working in 0.8.1.1 Deletion ...READ MORE

answered Sep 4, 2018 in Apache Kafka by nitinrawat895
• 10,920 points
446 views
+1 vote
10 answers

Writing the Kafka consumer output to a file

System.out.println(String.valueOf(output.offset()) + ": " + new String(bytes, ...READ MORE

answered Dec 7, 2018 in Apache Kafka by Harsh
12,804 views
0 votes
1 answer

What is the optimum number of producers to create in Kafka?

In general, a single producer for all ...READ MORE

answered Jul 10, 2018 in Apache Kafka by nitinrawat895
• 10,920 points
2,669 views
+1 vote
1 answer

Hadoop Mapreduce word count Program

Firstly you need to understand the concept ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 10,920 points
5,063 views
0 votes
1 answer

hadoop.mapred vs hadoop.mapreduce?

org.apache.hadoop.mapred is the Old API  org.apache.hadoop.mapreduce is the ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 10,920 points
719 views
+1 vote
11 answers

hadoop fs -put command?

put syntax: put <localSrc> <dest> copy syntax: copyFr ...READ MORE

answered Dec 7, 2018 in Big Data Hadoop by Aditya
29,845 views
–1 vote
1 answer

Hadoop dfs -ls command?

In your case there is no difference ...READ MORE

answered Mar 16, 2018 in Big Data Hadoop by kurt_cobain
• 9,310 points
1,890 views
0 votes
1 answer

How can I create a topic in apache kafka?

Hi@akhtar, To create kafka topic you can use ...READ MORE

answered Feb 6 in Apache Kafka by MD
• 22,020 points
66 views