0

I'm getting java.lang.NoClassDefFoundError which is caused by java.lang.ClassNotFoundException. I have added cassandra-driver-core-2.1.7.jar in build path. No compile time error but during runtime I'm getting above exception.

public class SimpleClient {
       private Cluster cluster;    
       public void connect(String node) {
           System.getProperties();
           try{
              cluster = Cluster.builder() ---> Here I'm getting java.lang.NoClassDefFoundError
                    .addContactPoint(node).build();
              Metadata metadata = cluster.getMetadata();
              System.out.printf("Connected to cluster: %s\n", 
                    metadata.getClusterName());
              for ( Host host : metadata.getAllHosts() ) {
                 System.out.printf("Datatacenter: %s; Host: %s; Rack: %s\n",
                       host.getDatacenter(), host.getAddress(), host.getRack());
              }
           }catch(Exception e){
               System.out.println(e.getMessage());
           }
       }

       public void close() {
          cluster.close();
       }

       public static void main(String[] args) {
          SimpleClient client = new SimpleClient();
          System.getProperties();
          client.connect("127.0.0.1");
          client.close();
       }
    }
DeepVeen
  • 299
  • 1
  • 5
  • 14
  • Can you please provide the exception? It would be useful to know what is missing. – Andy Tolbert Jan 06 '16 at 17:22
  • Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory at com.datastax.driver.core.Cluster.(Cluster.java:64) at SimpleClient.connect(SimpleClient.java:11) at SimpleClient.main(SimpleClient.java:32) Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory 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 at sun.misc.Launcher$AppClassLoader.loadClass at java.lang.ClassLoader.loadClass – DeepVeen Jan 06 '16 at 17:23
  • 1
    I see, I think you need to add the slf4j-api.jar file to your classpath. – Andy Tolbert Jan 06 '16 at 17:24
  • Yeah, this really isn't a duplicate...and the linked question doesn't have anything to do with Cassandra. This problem is actually semi-common to see while getting started on a new Cassandra project. – Aaron Jan 06 '16 at 19:29

0 Answers0