When I first tried to run “cassandra-cli” from the “bin” directory after unpacking the cassandra 0.6.3 package on my Windows system, I got a “NoClassDefFoundError” error. The exact command, context and error are shown below.
Starting Cassandra Client
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/cassandra/
cli/CliMain
Caused by: java.lang.ClassNotFoundException: org.apache.cassandra.cli.CliMain
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: org.apache.cassandra.cli.CliMain. Program will e
xit.
Java veterans would immediately suspect a problem with the class library search path with this type of error. I did too, so I added some environment variable echo statements to the “cassandra_cli.bat” file and found that the batch file was not pointing to the “lib” directory where Cassandra’s “*.jar” files were kept.
Normally, I’d be tempted to fix this by changing:
for %%i in (%CASSANDRA_HOME%\lib\*.jar) do call :append %%~fi
…in line #28 of my default “cassandra_cli.bat” file to:
for %%i in (%CASSANDRA_HOME%\..\lib\*.jar) do call :append %%~fi
…so my batch file could go back far enough to find the appropriate Cassandra class paths.
However, please don’t do that. Instead, Cassandra assumes that you’ll be running all your command-line utilities from the root Cassandra directory (e.g., “C:\Work\apache-cassandra-0.6.3″ instead of “C:\Work\apache-cassandra-0.6.3\bin”).
Instead, please just “cd ..” back to your root Cassandra folder and prepend “bin\” before your commands. Better results are shown below.
Starting Cassandra Client
Connected to: "Test Cluster" on localhost/9160
Welcome to cassandra CLI.
Type ‘help’ or ‘?’ for help. Type ‘quit’ or ‘exit’ to quit.
cassandra>
Published on Saturday July 03, 2010 at 09:34pm