70

I was trying to run Kafka on Windows machine and when I try to start the zookeeper I am facing this weird error:

classpath is empty. please build the project first e.g. by running 'gradlew jarall'

Dharman
  • 30,962
  • 25
  • 85
  • 135
Vishesh
  • 3,599
  • 4
  • 22
  • 36
  • 4
    I faced with the same problem. Problem arises when you download and use source downloads instead of binary downloads. – Safa Ozturk Jun 29 '17 at 08:27
  • 7
    Downloading binary and editing server.properties file seems to be the solution. – SelThroughJava Feb 16 '18 at 10:23
  • None of the above solutions helped. I downloaded binary (kafka_2.12-2.5.0.tgz) from this link: http://mirror.cc.columbia.edu/pub/software/apache/kafka/2.5.0/ and it worked. – Dexter404 Jul 12 '20 at 09:34
  • Check this fix https://i-am-jabi.medium.com/fixing-classpath-is-empty-69288c1509a2 – i.am.jabi Nov 14 '20 at 07:11
  • I tried every mentioned solution but its not working for me... Getting error: [0.005s][error][logging] Error opening log file '/c/kafka/bin/../logs/zookeeper-gc.log': No such file or directory [0.006s][error][logging] Initialization of output 'file=/c/kafka/bin/../logs/zookeeper-gc.log' using options 'filecount=10,filesize=100M' failed. Invalid -Xlog option '-Xlog:gc*:file=/c/kafka/bin/../logs/zookeeper-gc.log:time,tags:filecount=10,filesize=100M', see error log for details. Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. – Atmaram Jul 23 '22 at 12:17

21 Answers21

89

If anyone else is facing this issue:

  • Note: Do not download a source files from appache kafka, download a binary file
  • Download Kafka from here: Link
  • Also follow this link for any additional information
  • Also this group has some additional information
34

I had the exact same problem and I finally solved it. the problem is that you have space character in your path (inside folder names) which causes "dirname" command to receive more than one argument.

Therefore, in order to solve, you only need to remove space from folder names within your Kafka folder path.

mm49307
  • 2,490
  • 2
  • 19
  • 15
  • 1
    Yes, I was using Mac OS & had same problem. Moved the kafka folder to another location such that I did not have the space in the path anymore . Thanks a ton – Sagar Mhatre Feb 20 '23 at 09:03
20

Follow below steps for windows & kafka 0.9.0.0 (same steps will go with lower versions of kafka) First download binary from: https://www.apache.org/dyn/closer.cgi?path=/kafka/0.9.0.0/kafka_2.11-0.9.0.0.tgz

extract to your particular folder and then

Step 1: create new directories in your kafka directory

 - kafka-logs
 - zookeeper

your directory after step 1 will be :

 - bin 
 - config
 - kafka-logs
 - libs
 - site-docs
 - zookeeper

Step 2: Open config/server.properties and change below property

 - log.dirs={fullpath}/kafka-logs

Step 3: Open config/zookeeper.properties and change belwo property

 - dataDir={fullpath}/zookeeper

Step 4: create a run.bat file under bin/windows folder with following script:

start zookeeper-server-start.bat ..\..\config\zookeeper.properties

TIMEOUT 10

start kafka-server-start.bat ..\..\config\server.properties

exit

You can change timeout for your convenience.

usman
  • 1,351
  • 5
  • 23
  • 47
14

Here i think you downloaded kafka source. you need to download binary

https://www.apache.org/dyn/closer.cgi?path=/kafka/0.9.0.0/kafka_2.11-0.9.0.0.tgz

sreejith
  • 716
  • 5
  • 20
9

Follow below steps to resolve this error.

step1: Get inside kafka downloaded folder

cd kafka-2.5.0-src

step2: Run gradle

./gradlew jar 

step3: Once build is successful, start the kafka server

bin/zookeeper-server-start.sh config/zookeeper.properties
bin/kafka-server-start.sh config/server.properties

Now Kafka will be starts on localhost:9092

Suthanth DK
  • 127
  • 2
  • 8
5

Had the same problem and it was because I download the source file instead of the binary file.

5

Simple ensure there are no white spaces in your folder hierarchy

for example: instead of -> "c:\desktop\work files\kafka_2.12-2.7.0"

use this -> "c:\desktop\work-files\kafka_2.12-2.7.0"

this worked for me!

RichOtaru
  • 51
  • 1
  • 2
2

If you are using the Kafka source to run the Kafka server on the Windows 10 machine. We need to build the source first using the below step.

Please note: we need to have gradle build tool installed and path variable set before following the below steps.

  1. Open the command prompt and navigate to the Kafka home directory

    C:\kafka-1.1.1-src>

  2. Enter the command 'gradle' and press Enter

    C:\kafka-1.1.1-src>gradle

  3. Once the build is successful enter the below command

    C:\kafka-1.1.1-src>gradlew jar

  4. Now enter the below command to start the server

    C:\kafka-1.1.1-src>.\bin\windows\kafka-server-start.bat .\config\server.properties

If everything went fine, your command prompt will look like this one enter image description here

Rajesh
  • 4,273
  • 1
  • 32
  • 33
  • Thanks @Rajesh , step 3 doesn't work for me even though step 2 went through all right - BUILD SUCCESSFUL in 13s; in step 3 I get: gradlew is not recognized as an internal or external command.... – Teo Mar 18 '20 at 11:20
  • 1
    If gradle is installed and gradle path is set on your machine just replace the gradlew with gradle. – Rajesh Mar 18 '20 at 11:40
2

Ensure that you have no white space or special character

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – PaulSCoder Oct 10 '21 at 21:34
2

Step 1 : Navigate to \confluent-community-5.5.0–2.12\confluent-5.5.0\bin\windows folder.

Step 2: Open kafka-run-class.bat file.

Step 3 : Search rem Classpath addition for core in this bat file

Step 4: Now, just add the below code just above the rem Classpath addition for core line.

rem classpath addition for LSB style path
if exist %BASE_DIR%\share\java\kafka\* (
call:concat %BASE_DIR%\share\java\kafka\*
)
Ehsan Akbar
  • 6,977
  • 19
  • 96
  • 180
1

Using Windows 10:

  1. Download and extract bin kafka and change the config/server.properties; for me it changes from

    log.dirs=/tmp/kafka-logs
    

    to

    log.dir= D:\Elastic_search\kafka_2.11-0.9.0.0\kafka-logs
    

    Create the new directory, kafka-logs.

  2. Run

    .\bin\windows\kafka-server-start.bat .\config\server.properties
    

    in your root kafka_2.11-0.9.0.0 folder with CMD "again"

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
Rizki
  • 11
  • 1
1

I found that the bit of code below that adds to the Classpath was missing from \bin\windows\kafka-run-class.bat from the previous version I was using. (Confluent 4.0.0 vs 5.3.1)

rem Classpath addition for LSB style path
if exist %BASE_DIR%\share\java\kafka\* (
   call :concat %BASE_DIR%\share\java\kafka\* 
)
  • Hi ! I see that you are a new contributor. Welcome ! In the purpose of clarifying your answer, can you elaborate on why do you think this solves the issue ? If you are not the author of the code sniplet, pointing to the original source is also helpfull! Thanks ! – Auyer Dec 05 '19 at 21:50
  • When I tried it on a computer with no Classpath set, I would get the error described above. If I hard coded a Classpath, I would get "Error: Could not find or load main class org.apache.zookeeper.server.quorum.QuorumPeerMain". Inspecting kafka-run-class.bat shows several sections noted with rem Classpath addition..., but I don't have any of the folders it is checking for in the fileset I downloaded. (Confluent 5.3.1 with kafka 2.12. When I add the snippet of code above the kafka-run-class.bat, exist %BASE_DIR%\share\java\kafka\* was true and my Classpath was no longer blank. – Eric Hughes Dec 06 '19 at 23:15
  • The snippet has to be added before the code - IF not defined CLASSPATH ( echo Classpath is empty. Please build the project first e.g. by running 'gradlew jarAll' – Eric Hughes Dec 06 '19 at 23:18
  • You can find the code you that fixed it for me on line 97 of kafka-run-class-bat in this confluent archive tar. https://packages.confluent.io/archive/4.0/confluent-4.0.0-2.11.tar.gz – Eric Hughes Dec 06 '19 at 23:40
0

I followed the link https://janschulte.wordpress.com/2013/10/13/apache-kafka-0-8-on-windows/ to configure kafka and it worked. But I used the same version as mentioned in the post (which is old version). For now I need kafka for my project so decided to proceed with the version.

Few things the author missed out in the explanation. Please find them below

1) After downloading the sbt windows installer, you need to restart the system not only the shell,to reflect the necessary changes

2) Add the following in the 66,67th line of kafka-run-class.sh

JAVA="java"

$JAVA $KAFKA_OPTS $KAFKA_JMX_OPTS -cp cygpath -wp $CLASSPATH "$@" (Make sure your java is configured in environment variables)

3) Traverse to the appropriate path, to run the zookeeper command bin/zookeeper-server-start.sh config/zookeeper.properties

Tag me if you have any doubts! Happy to Help!

Running!

Aravind Krishnakumar
  • 2,727
  • 1
  • 28
  • 25
  • Aravind Krishnakumar thanks for the help... I was caught up in some other work .. Will try the solution and update you soon. – Vishesh Dec 11 '15 at 05:53
0

I sufferred the same issue. Download the zookeeper tar file as well. Downloading the zookeeper in the same folder and then typing the same commands worked for me.

0

Guys be sure that you are using the right path to zookeeper.properties file. In my occassion I was using the full path for the .bat file and a wrong relative path for the .properties file. Having a wrong path to zookeeper.properties will produce the error that you mentioned. Notice that I have used the binary, not the kafka source.

Giorgos Myrianthous
  • 36,235
  • 20
  • 134
  • 156
0

For me the issue was when unzipping the files. I moved them to another folder, and something went wrong. I unzipped again keeping the directory structure, and it worked.

thanks to orlando mendez for the advice! https://www.youtube.com/watch?v=7F9tBwTUSeY

A. Kearns
  • 1
  • 1
0

This happened to me when the length of Kafka folder path was long. Try it with a shorter path like "D:\kafka_2.12-2.7.0"

0

Please download binary package, not source code.

harun ugur
  • 1,718
  • 18
  • 18
0

I faced the same issue, this is what worked for me

  1. I downloaded the binary version I Created the directory as following C:/kafka
  2. Changed the properties files
  3. Changes in zookeeper.properties -
    dataDir=C:/kafka/zookeeper-data
  4. Changes in server.properties - log.dirs = C:/kafka/kafka-logs

All the directories got created automatially

This should work. Video for reference -
https://www.youtube.com/watch?v=3XjfYH5Z0f0

Vibhor Dube
  • 4,173
  • 1
  • 22
  • 32
0

Download the Kafka binaries not source or make sure there are no empty characters in file paths

mesutpiskin
  • 1,771
  • 2
  • 26
  • 30
0

This site describes a solution that worked for me. The solution was to modify a bat file so that java knows the path of several jar libs. Of cource I downloaded the binary and not source files from confluent.