RSS
 

How do I fix a “NoClassDefFoundError” while attempting to start Cassandra?

03 Jul

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.

C:\Work\apache-cassandra-0.6.3\bin>cassandra-cli -host localhost -port 9160
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.

C:\Work\apache-cassandra-0.6.3>bin\cassandra-cli  -host localhost -port 9160
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>

About Jonathan Lampe

Author of 43 articles on this blog.

I have about 12 years of experience designing secure, partially distributed systems (e.g., web farm with some extra load in one remote data center), often in industries such as finance and defense. My solutions and software are currently deployed in mission-critical roles at about 1000 enterprises worldwide. In the last 2-3 years I have turned my technical attention toward more geographically distributed systems and heterogeneous environments (e.g., a mix of operating systems or on-premises and cloud deployments) while maintaining my focus on good UX and great security.

Share

Published on Saturday July 03, 2010 at 09:34pm

 
Comments Off

Posted in Beginner, Cassandra, Troubleshooting

 

Comments are closed.