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

Shark picture Shark · Feb 12, 2015 · Viewed 39.5k times · Source

(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);

Answer

Onnonymous picture Onnonymous · Jun 17, 2019

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