Exception in main thread java.lang.NoClassDefFoundError

ε祈祈猫儿з 提交于 2019-12-21 22:10:52

问题


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

回答1:


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!




回答2:


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.




回答3:


i too faced the same issue but after adding the following jars the issue get resolved, 1. bsh-2.0b4.jar 2. guava-16.0.1.jar 3. jcommander-1.27.jar 4. log4j-1.2.17.jar 5. lz4-1.2.0.jar 6. metrics-core-3.0.2.jar 7. netty-3.9.0.Final 8. slf4j-api-1.7.5.jar 9. slf4j-log4j12-1.7.6.jar 10. snappy-java-1.0.5.jar.

hope this will help you :)



来源:https://stackoverflow.com/questions/25803092/exception-in-main-thread-java-lang-noclassdeffounderror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!