Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Starting Zookeeper Cluster. Error: Could not find or load main class org.apache.zookeeper.server.quorum.QuorumPeerMain

(I'm running on CentOS 5.8). I've been following the direction for a Clustered (Multiserver) Zookeeper Set-up, but getting an error when I try to start up my server. When I run the command as described in the documentation:

java -cp zookeeper-3.4.6.jar:lib/log4j-1.2.16.jar:conf \ org.apache.zookeeper.server.quorum.QuorumPeerMain conf/zoo.cfg 

I get the error:

Error: Could not find or load main class  org.apache.zookeeper.server.quorum.QuorumPeerMain

I have my files location as such and am running from the ~/zookeeper-3.4.6 directory:

~/zookeeper-3.4.6/zookeeper-3.4.6.jar 
~/zookeeper-3.4.6/conf/zoo.cfg
~/zookeeper-3.4.6/data/myid
~/zookeeper-3.4.6/lib/log4j-1.2.16.jar
~/zookeeper-3.4.6/bin/zkServer.sh

Does anyone know why this error is happening? I don't quite understand the arguments that are being passed, so it is hard for me to debug the path issue. As a side note, I've tried running ./zookeeper-3.4.6/bin/zkServer.sh start, which did successfully work, but the documentation seems to indicate that command is meant for a single-node instance.

Edit:

I was able to make some progress by modifying the command and taking out the :conf \ part, so now I'm running:

java -cp zookeeper-3.4.6.jar:lib/log4j-1.2.16.jar: org.apache.zookeeper.server.quorum.QuorumPeerMain conf/zoo.cfg

I get a new error, but this is progress...

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFacto
ry
        at org.apache.zookeeper.server.quorum.QuorumPeerMain.<clinit>(QuorumPeer
Main.java:64)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
        ... 1 more

which corresponds to lines 63 and 64 from QuorumPeerMain

public class QuorumPeerMain {
    private static final Logger LOG = LoggerFactory.getLogger(QuorumPeerMain.class);
like image 824
Shark Avatar asked Feb 12 '15 17:02

Shark


3 Answers

I got the Error: Could not find or load main class org.apache.zookeeper.server.quorum.QuorumPeerMain, because I had downloaded the apache-zookeeper-X.X.X.tar.gz file and not the apache-zookeeper-X.X.X.bin.tar.gz file. Downloading, untarring and using the bin.tar file fixed it for me.

You can also build the binaries from the apache-zookeeper-X.X.X.tar.gz file; see the answer of @vincent.

like image 173
Onnonymous Avatar answered Sep 20 '22 10:09

Onnonymous


This happens when you download and used apache-zookeeper-X.X.X.tar.gz, you should use apache-zookeeper-X.X.X-bin.tar.gz. this will surely solve this issue

like image 27
Antro Francis Avatar answered Sep 21 '22 10:09

Antro Francis


The issue can be solved by untaring apache-zookeeper-3.5.6-bin.tar.gz. Initially, I encountered the same error while untared/installed apache-zookeeper-3.5.6.tar.gz and executed /bin/zkServer.sh start

Please make sure you have downloaded apache-zookeeper-3.5.6-bin.tar.gz

like image 36
Gautam Avatar answered Sep 20 '22 10:09

Gautam