11

I am using kafka on window by Cygwin and trying to create a topic and getting the below error

log4j:ERROR Could not read configuration file from URL [file:/cygdrive/d/kafka/bin/../config/tools-log4j.properties].
java.io.FileNotFoundException: \cygdrive\d\kafka\bin\..\config\tools-log4j.properties (The system cannot find the path specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.io.FileInputStream.<init>(Unknown Source)
    at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
    at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:524)
    at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:483)
    at org.apache.log4j.LogManager.<clinit>(LogManager.java:127)
    at org.apache.log4j.Logger.getLogger(Logger.java:117)
    at org.I0Itec.zkclient.ZkClient.<clinit>(ZkClient.java:57)
    at kafka.admin.TopicCommand$.main(TopicCommand.scala:51)
    at kafka.admin.TopicCommand.main(TopicCommand.scala)
log4j:ERROR Ignoring configuration file [file:/cygdrive/d/kafka/bin/../config/tools-log4j.properties].
log4j:WARN No appenders could be found for logger (org.I0Itec.zkclient.ZkEventThread).
log4j:WARN No appenders could be found for logger (org.I0Itec.zkclient.ZkConnection).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

But the topic is getting created. Can you help me on this

1209
  • 159
  • 1
  • 3
  • 10

4 Answers4

12

Are you creating the topic using this command line from the Kafka documentation?

bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

I encountered the same error when running that script in Cygwin, and I made this change in bin/kafka-run-class.sh to resolve the problem (similar to the Cygwin classpath solution referenced in step 3 of the first answer here):

Original:

# Log4j settings if [ -z "$KAFKA_LOG4J_OPTS" ]; then KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:$base_dir/config/tools-log4j.properties" fi

To:

# Log4j settings if [ -z "$KAFKA_LOG4J_OPTS" ]; then KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:$(cygpath -wp $base_dir/config/tools-log4j.properties)" fi

Krzysztof Atłasik
  • 21,985
  • 6
  • 54
  • 76
Ben Thomas
  • 121
  • 1
  • 4
  • 4
    Seems like they updated that script to look for Cygwin but if you try to use Git Bash like me you'll still get the error :P – b15 May 06 '19 at 21:32
  • I was receiving the same error with git bash. Worked like a charm! – dane131 Apr 26 '20 at 10:43
8

I ran the .bat script instead of .sh script and it worked. I didn't have to change anything.

Initially I ran this script in git bash;

bin/kafka-console-consumer.sh --boostrap-server localhost:9092 --topic kafkaTopic

and got the following error:

$ bin/kafka-console-consumer.sh --boostrap-server localhost:9092 --topic kafkaTopic
log4j:ERROR Could not read configuration file from URL
[file:/c/Users/admin/Documents/kafka/bin/../config/tools-log4j.properties].
java.io.FileNotFoundException: 

\c\Users\admin\Documents\kafka\bin\..\config\tools-log4j.properties
(The system cannot find the path specified)
      at java.io.FileInputStream.open0(Native Method)
      at java.io.FileInputStream.open(FileInputStream.java:195)
      at java.io.FileInputStream.<init>(FileInputStream.java:138)
      at java.io.FileInputStream.<init>(FileInputStream.java:93)
      at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:90)
      at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:188)
      at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:557)
      at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:526)
      at org.apache.log4j.LogManager.<clinit>(LogManager.java:127)
      at org.slf4j.impl.Log4jLoggerFactory.<init>(Log4jLoggerFactory.java:66)
      at org.slf4j.impl.StaticLoggerBinder.<init>(StaticLoggerBinder.java:72)
      at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:45)
      at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
      at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
      at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)
      at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)
      at com.typesafe.scalalogging.Logger$.apply(Logger.scala:48)
      at kafka.utils.Log4jControllerRegistration$.<init>(Logging.scala:25)
      at kafka.utils.Log4jControllerRegistration$.<clinit>(Logging.scala)
      at kafka.utils.Logging.$init$(Logging.scala:47)
      at kafka.tools.ConsoleConsumer$.<init>(ConsoleConsumer.scala:45)
      at kafka.tools.ConsoleConsumer$.<clinit>(ConsoleConsumer.scala)
      at kafka.tools.ConsoleConsumer.main(ConsoleConsumer.scala)

I opened cmd and ran the command below:

C:\Users\admin\Documents\kafka\bin\windows>kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic kafkaTopic

Output:

{"message":"Spring Kafka is cool","sender":"Sydney"}

Worked nicely :)

RobC
  • 22,977
  • 20
  • 73
  • 80
Sydney Molobela
  • 193
  • 3
  • 10
1

I think the path you have mentioned is incorrect. As the message says File Not Found Exception. Below is a sample code to send messages to kafka in Java. Assuming Kafka server is running locally.

`public static void main(String[] args){
    long events = 100000;
    Random rnd  = new Random();

    Properties props = new Properties();
    props.put("metadata.broker.list", "localhost:9092");
    props.put("serializer.class", "kafka.serializer.StringEncoder");
    props.put("partitioner.class", "com.pranjal.kafkatest.SimplePartitioner");
    props.put("request.required.acks", "1");

    ProducerConfig config = new ProducerConfig(props);

    Producer<String, String> producer = new Producer<String, String>(config);

    for(int i=0;i<events;++i){

        long runtime = new Date().getTime();
        String ip    = "192.168.2." + rnd.nextInt(255);

        String msg= "Hello";

        KeyedMessage<String, String> data = new KeyedMessage<String, String>("sentences", ip, msg);
        producer.send(data);
    }
    producer.close();
}`
Pranjal Sahu
  • 1,469
  • 3
  • 18
  • 27
  • i have not done any path setting can you help me where should i do that – 1209 Apr 10 '15 at 05:36
  • Btw there is no problem with this message as it is only related to logging utilities **\cygdrive\d\kafka\bin..\config\tools-log4j.properties**. That is why your topic is being created correctly inspite of this error message. No worries. – Pranjal Sahu Apr 10 '15 at 06:26
  • thank you.can you help me with the sample code of sending messages to kafka with java – 1209 Apr 13 '15 at 05:53
  • Thanks a lot sahu.How can i view the messges in the topic whether they are sent or not – 1209 Apr 15 '15 at 06:06
  • Use console consumer. It is present in bin directory of kafka. – Pranjal Sahu Apr 15 '15 at 08:41
  • Yes i tried it getting the below error log4j:ERROR Could not read configuration file from URL – 1209 Apr 15 '15 at 08:58
  • Any sample code to fetch the nimber of messges in a topic – 1209 Apr 17 '15 at 06:17
1

Using .bat worked for me. below are the sequence of commands:-

  1. cd kafka_2.13-3.3.1
  2. .\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties
  3. .\bin\windows\kafka-server-start.bat .\config\server.properties
  4. \bin\windows\kafka-topics.bat --create --topic quickstart-events --bootstrap-server localhost:9092

Output:- Created topic quickstart-events.

iAviator
  • 1,310
  • 13
  • 31