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, 2020 in Apache Kafka by akhtar
• 38,230 points
754 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, 2020 by MD
• 95,440 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
• 11,380 points
2,093 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
• 11,380 points
1,529 views
+2 votes
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
36,741 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
• 11,380 points
7,946 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
• 11,380 points
10,558 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
• 11,380 points
2,185 views
+2 votes
11 answers

hadoop fs -put command?

Hi, You can create one directory in HDFS ...READ MORE

answered Mar 16, 2018 in Big Data Hadoop by nitinrawat895
• 11,380 points
104,214 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,390 points
4,260 views
0 votes
1 answer

What is a producer in Kafka Cluster?

Hi@akhtar, The Kafka producer is conceptually much simpler than the ...READ MORE

answered Dec 7, 2020 in Apache Kafka by MD
• 95,440 points
549 views
0 votes
1 answer

What is a broker in Kafka Cluster?

Hi@akhtar, A Kafka broker receives messages from producers and stores ...READ MORE

answered Dec 7, 2020 in Apache Kafka by MD
• 95,440 points
1,324 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP