Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception in main thread java.lang.NoClassDefFoundError

Getting error Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/util/concurrent/FutureCallback, while running below code. Pls advise which Jar file am missing. I am executing from Eclipse IDE

package Datastax;

import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Host;
import com.datastax.driver.core.Metadata;
import com.datastax.driver.core.Session;


public class DataStaxPOC {
   private Cluster cluster;

   public void connect(String node) {

       cluster = Cluster.builder().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());
      }
   }

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

   public static void main(String[] args) {
      DataStaxPOC client = new DataStaxPOC();
      client.connect("127.0.0.1");
      client.close();
   }
}
like image 296
Ranjeeth Avatar asked Feb 13 '26 19:02

Ranjeeth


2 Answers

to setup your environment, you'll need the following resources:

  • cassandra-driver-core-2.1.0.jar
  • netty-3.9.0-Final.jar
  • guava-16.0.1.jar
  • metrics-core-3.0.2.jar
  • slf4j-api-1.7.5.jar

(as outlined in this link: http://www.datastax.com/documentation/developer/java-driver/2.1/java-driver/reference/settingUpJavaProgEnv_r.html)

Otherwise you could use Maven if you are using an IDE like Eclipse. See the following link for a dependancy example: http://www.datastax.com/documentation/developer/java-driver/2.1/common/drivers/introduction/driverDependencies_r.html

Note you also need to ensure that the the start_native_transport: true is in your cassandra.yaml configuration file also outlined in the above link.

To install Maven into Eclipse I'd recommend using this excellent step-by-step: Maven in Eclipse: step by step installation

Hope this helps!

like image 82
markc Avatar answered Feb 15 '26 13:02

markc


You need to have cassandra-driver-core-2.0.1.jar , netty-3.9.0-Final.jar , guava-16.0.1.jar , metrics-core-3.0.2.jar , and slf4j-api-1.7.5.jar on the classpath.

like image 38
Chamila Wijayarathna Avatar answered Feb 15 '26 12:02

Chamila Wijayarathna



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!