我安装了titan-cassandra-0.4.4
,我可以完美运行cassandra和gremlin(本地节点)。
我想用 Java 测试一个算法,所以我需要将 Java 连接到 titan。 我的 pom 是:
<dependency>
<groupId>com.thinkaurelius.titan</groupId>
<artifactId>titan-core</artifactId>
<version>0.4.4</version>
</dependency>
我的代码是:
BaseConfiguration baseConfiguration = new BaseConfiguration();
baseConfiguration.setProperty("storage.backend", "cassandra");
baseConfiguration.setProperty("storage.hostname", "127.0.0.1");
baseConfiguration.setProperty("storage.tablename","test");
TitanGraph titanGraph = TitanFactory.open(baseConfiguration);
在最后一行,错误是:
Exception in thread "main" java.lang.NoClassDefFoundError: com/netflix/astyanax/connectionpool/exceptions/ConnectionException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.thinkaurelius.titan.diskstorage.Backend.getStorageManager(Backend.java:202)
at com.thinkaurelius.titan.diskstorage.Backend.<init>(Backend.java:97)
at com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration.getBackend(GraphDatabaseConfiguration.java:398)
at com.thinkaurelius.titan.graphdb.database.StandardTitanGraph.<init>(StandardTitanGraph.java:78)
at com.thinkaurelius.titan.core.TitanFactory.open(TitanFactory.java:60)
at Connecting.main(Connecting.java:20)
Caused by: java.lang.ClassNotFoundException: com.netflix.astyanax.connectionpool.exceptions.ConnectionException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 8 more
我先启动cassandra,然后titan gremlin.sh,最后运行java代码。不知道是不是漏了什么?
提前致谢!
最佳答案
您应该包含对 titan-casssandra
的依赖。
<dependency>
<groupId>com.thinkaurelius.titan</groupId>
<artifactId>titan-casssandra</artifactId>
<version>0.4.4</version>
</dependency>
另请注意,如果您刚刚开始使用 Titan,版本 0.4.4 已经过时了。 Titan 1.0 于 2015 年 9 月发布。您可以在 http://titandb.io 找到更多信息。
关于java - 如何将 Java 与带有嵌入式 Cassandra 的 Titan 连接起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33679535/