2015-11-12 49 views
1

我安裝了titan-cassandra-0.4.4,我可以完美地運行cassandra和gremlin(本地節點)。如何連接Java與泰坦與嵌入式卡桑德拉

我想在Java中測試一個算法,所以我需要將Java連接到泰坦。 我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 

我第一次開始卡桑德拉的話,泰坦gremlin.sh ,最後運行java代碼。我不知道我是否錯過了一些東西?

提前致謝!

回答

3

您應該包含titan-casssandra的依賴關係。

<dependency> 
     <groupId>com.thinkaurelius.titan</groupId> 
     <artifactId>titan-casssandra</artifactId> 
     <version>0.4.4</version> 
    </dependency> 

另外請注意,如果你剛剛開始使用泰坦,版本0.4.4是遠遠過時。 Titan 1.0於2015年9月發佈。您可以在http://titandb.io