classpath is empty. please build the project first
Asked Answered
H

21

78

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'

Halfon answered 4/12, 2015 at 5:14 Comment(5)
I faced with the same problem. Problem arises when you download and use source downloads instead of binary downloads.Insoluble
Downloading binary and editing server.properties file seems to be the solution.Elastance
None of the above solutions helped. I downloaded binary (kafka_2.12-2.5.0.tgz) from this link: mirror.cc.columbia.edu/pub/software/apache/kafka/2.5.0 and it worked.Ontina
Check this fix i-am-jabi.medium.com/fixing-classpath-is-empty-69288c1509a2Flyweight
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.Ribwort
T
97

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
Tungusic answered 18/9, 2017 at 9:34 Comment(2)
does this mean we are forced to use Scala, as all binary downloads are available for scala only?Mastoiditis
I'm still getting the same error as the OP when downloading the binary file.....Parthinia
K
38

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.

Kemerovo answered 11/12, 2017 at 12:57 Comment(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 tonNonary
K
21

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.

Kulseth answered 4/12, 2015 at 13:24 Comment(4)
dear accept answer if that worked for you. also let us know which windows you are running on?Kulseth
Hi Usman... I was bit caught up in some other work. I will try the solution and update you.Halfon
This thing really works!!! Tnx a lot!Keble
Hello Usman. Below are my dir - dataDir=D:/Softwares/Kafka/kafka_2.12-3.6.1/zookeeper log.dirs=D:/Softwares/Kafka/kafka_2.12-3.6.1/kafka-logs However, when I execute the bat command from command prompt, a black screen flashing. This is the case for both of the commands. I tried restarting as well. Could you please help here?Trailer
S
15

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

Susceptive answered 4/12, 2015 at 6:0 Comment(2)
Hi Sreejith... i downloaded the binary itself... i have extracted itHalfon
Then i think you should add echo %CLASSPATH% in kafka-run-class.bat and find why jars in lib not adding to your classpathSusceptive
K
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

Kenney answered 3/6, 2020 at 19:15 Comment(0)
L
7

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!

Lietman answered 8/7, 2021 at 4:49 Comment(1)
I had folder name apache kafka and that was causing the problem. thanksMissile
L
5

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

Longboat answered 25/10, 2020 at 9:8 Comment(1)
Thank you so much for your comment! It saved my day :)Pollinate
C
4

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\*
)
Curse answered 25/1, 2022 at 9:34 Comment(0)
P
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

Prussian answered 27/7, 2018 at 11:13 Comment(2)
Thanks @Prussian , 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....Enyedy
If gradle is installed and gradle path is set on your machine just replace the gradlew with gradle.Prussian
R
2

Ensure that you have no white space or special character

Reactant answered 10/10, 2021 at 19:27 Comment(1)
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.Crisp
S
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"

Sperm answered 21/3, 2017 at 3:55 Comment(0)
V
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\* 
)
Violetavioletta answered 5/12, 2019 at 21:26 Comment(4)
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 !Airboat
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.Violetavioletta
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'Violetavioletta
You can find the code you that fixed it for me on line 97 of kafka-run-class-bat in this confluent archive tar. packages.confluent.io/archive/4.0/confluent-4.0.0-2.11.tar.gzVioletavioletta
D
1

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

Diagram answered 23/6, 2022 at 7:10 Comment(0)
T
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!

Thompson answered 6/12, 2015 at 12:12 Comment(1)
Aravind Krishnakumar thanks for the help... I was caught up in some other work .. Will try the solution and update you soon.Halfon
F
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.

Fudge answered 21/6, 2018 at 10:20 Comment(0)
T
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.

Twylatwyman answered 28/6, 2019 at 15:21 Comment(0)
H
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

Hoodoo answered 1/10, 2020 at 14:27 Comment(0)
J
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"

Jab answered 11/2, 2021 at 18:28 Comment(0)
G
0

Please download binary package, not source code.

Gemma answered 7/10, 2021 at 21:37 Comment(0)
M
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

Mutton answered 31/5, 2022 at 12:34 Comment(0)
G
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.

Grimonia answered 18/10, 2022 at 19:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.