无法从intellij生成的jar中打开与Cassandra的本机连接

时间:2016-12-18 12:48:37

标签: scala intellij-idea cassandra

我开发了一个基于spark的应用程序,它使用intellij从kafka获取数据并将其保存在cassandra数据库中。

scala中的连接代码:

val cluster = Cluster.builder().addContactPoint("192.168.0.253").withPort(9042).build();
val session = cluster.connect()

当我从intellij运行代码时,代码工作正常,但是当我尝试使用命令行从jar运行它时出现此错误:

Exception in thread "main" java.io.IOException: 
Failed to open native connection to Cassandra at {192.168.0.253}:9042 at .... ....
Caused by: com.datastax.driver.core.exceptions.NoHostAvailableException:

All host(s) tried for query failed 
(tried: /192.168.0.253:9042 (com.datastax.driver.core.exceptions.TransportException: 
[/192.168.0.253] Error writing)) at 

com.datastax.driver.core.ControlConnection.reconnectInternal(
ControlConnection.java:233) at
com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:79) 
at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1424) 
at com.datastax.driver.core.Cluster.getMetadata(Cluster.java:403) 
at com.datastax.spark.connector.cql.CassandraConnector$.
com$datastax$spark$connector$cql$CassandraConnector$$createSession(
CassandraConnector.scala:155) ... 13 more

我已经从intellij生成了一个jar文件,我使用[copy to the output directory and link via showsist]选项构建了带依赖关系的jar。

cassandra.yaml文件:

#Whether to start the native transport server. 
start_native_transport: true
#port for the CQL native transport to listen for clients on
native_transport_port: 9042

为什么会出现此错误&我该如何解决?

提前致谢

0 个答案:

没有答案