我的Jar文件
cassandra-driver-core-2.1.0.jar
我对com/datastax/driver/core/Cluster
javap -classpath cassandra-driver-core-2.1.0.jar com/datastax/driver/core/Cluster
显示
public class com.datastax.driver.core.Cluster implements java.io.Closeable {
final com.datastax.driver.core.Cluster$Manager manager;
protected com.datastax.driver.core.Cluster(java.lang.String, java.util.List<java.net.InetSocketAddress>, com.datastax.driver.core.Configuration);
protected com.datastax.driver.core.Cluster(com.datastax.driver.core.Cluster$Initializer);
public com.datastax.driver.core.Cluster init();
public static com.datastax.driver.core.Cluster buildFrom(com.datastax.driver.core.Cluster$Initializer);
public static com.datastax.driver.core.Cluster$Builder builder();
...............
我的Java文件是
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Host;
import com.datastax.driver.core.Metadata;
public class SimpleClient {
private Cluster cluster;
public void connect(String node) {
System.out.println("I am in");
cluster = Cluster.builder().addContactPoint(node).build();
//ERROR
}
public void close() {
cluster.close();
}
public static void main(String[] args) {
SimpleClient client = new SimpleClient();
System.out.println("Obj Created");
client.connect("127.0.0.1");
// client.close();
}
}
我的编译命令是
javac -classpath cassandra-driver-core-2.1.0.jar SimpleClient.java
我的跑步命令
tried1: java -classpath cassandra-driver-core-2.1.0.jar SimpleClient
说
Could not find or load main class SimpleClient
但是课堂已经存在。
Tried2: java -classpath SimpleClient
它说
Obj Created
I am in
Exception in thread "main" java.lang.NoClassDefFoundError: com/datastax/driver/core/Cluster
at SimpleClient.connect(SimpleClient.java:12)
at SimpleClient.main(SimpleClient.java:29)
Caused by: java.lang.ClassNotFoundException: com.datastax.driver.core.Cluster
请让我知道解决方案。
答案 0 :(得分:0)
你必须使用
java -classpath ./;cassandra-driver-core-2.1.0.jar SimpleClient
在Windows机器上
或
java -classpath ./:cassandra-driver-core-2.1.0.jar SimpleClient
在linux机器上。
这会将实际目录添加到类路径中。