最近在研究圖計算相關技術,前一階段學了Neo4j的知識,在學習的過程也對比一些其它的開源圖數據庫,如OrientDB,還有一些通用框架TinkerPop。html
在OrientDB的對比學習過程當中,但願首先把已有的數據導入到新的數據庫中,還好OrientDB官方提供了Neo4j數據導入工具orientdb-neo4j-importer。然而一切皆有坑...java
按照官方文檔進行數據導入,執行命令:node
sh orientdb-neo4j-importer-2.2.31/bin/orientdb-neo4j-importer.sh -neo4jdbdir ../graph.db/ -neo4jlibdir ../neo4jlib/
出現如下報錯:數據庫
Exception in thread "main" java.lang.NoClassDefFoundError: com/orientechnologies/orient/core/OConstants at com.orientechnologies.orient.neo4jimporter.ONeo4jImporterMain.main(ONeo4jImporterMain.java:15) Caused by: java.lang.ClassNotFoundException: com.orientechnologies.orient.core.OConstants 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) ... 1 more
嘗試把importer/lib/orientdb-neo4j-importer-2.2.31.jar拷貝到orientdb安裝目錄的lib文件夾下,再次執行仍是一樣的報錯。框架
查看源代碼也沒發現此處有問題,再經過sh打印詳細信息發現環境變量ORIENTDB_HOME設置有問題,執行如下命令定義環境變量:工具
export ORIENTDB_HOME=/root/orientdb-community-importers-2.2.31
再次執行命令,順利經過!學習
[root@datanode orientdb-community-importers-2.2.31]# sh -x orientdb-neo4j-importer-2.2.31/bin/orientdb-neo4j-importer.sh -neo4jdbdir ../graph.db/ -neo4jlibdir ../neo4jlib/ + PRG=orientdb-neo4j-importer-2.2.31/bin/orientdb-neo4j-importer.sh + '[' -h orientdb-neo4j-importer-2.2.31/bin/orientdb-neo4j-importer.sh ']' ++ dirname orientdb-neo4j-importer-2.2.31/bin/orientdb-neo4j-importer.sh + PRGDIR=orientdb-neo4j-importer-2.2.31/bin + '[' -f /root/orientdb-community-importers-2.2.31/lib/orientdb-neo4j-importer-2.2.31.jar ']' + export ORIENTDB_HOME + '[' -f /usr/java/jdk1.8.0_91/bin/java ']' + JAVA=/usr/java/jdk1.8.0_91/bin/java + export JAVA + LOG_FILE=/root/orientdb-community-importers-2.2.31/config/orientdb-neo4j-importer-log.properties + JAVA_MAX_DIRECT=-XX:MaxDirectMemorySize=512g + JAVA_OPTS_SCRIPT='-XX:MaxDirectMemorySize=512g -Djava.util.logging.config.file=/root/orientdb-community-importers-2.2.31/config/orientdb-neo4j-importer-log.properties' + ARGS= + for var in '"$@"' + ARGS=' -neo4jdbdir' + for var in '"$@"' + ARGS=' -neo4jdbdir ../graph.db/' + for var in '"$@"' + ARGS=' -neo4jdbdir ../graph.db/ -neo4jlibdir' + for var in '"$@"' + ARGS=' -neo4jdbdir ../graph.db/ -neo4jlibdir ../neo4jlib/' + [[ 4 -gt 1 ]] + key=-neo4jdbdir + case $key in + shift + [[ 3 -gt 1 ]] + key=../graph.db/ + case $key in + shift + [[ 2 -gt 1 ]] + key=-neo4jlibdir + case $key in + NEO4JLIB=../neo4jlib/ + shift + shift + [[ 0 -gt 1 ]] + exec /usr/java/jdk1.8.0_91/bin/java -client -cp '../neo4jlib//*:/root/orientdb-community-importers-2.2.31/lib/*' -XX:MaxDirectMemorySize=512g -Djava.util.logging.config.file=/root/orientdb-community-importers-2.2.31/config/orientdb-neo4j-importer-log.properties com.orientechnologies.orient.neo4jimporter.ONeo4jImporterMain -neo4jdbdir ../graph.db/ -neo4jlibdir ../neo4jlib/ Neo4j to OrientDB Importer v.2.2.31 (build 285537d2767275f460df32c6a3be01bfff6a517c, branch 2.2.x) - Copyrights (c) 2016 OrientDB LTD WARNING: 'o' option not found. Defaulting to 'false'. WARNING: 'i' option not found. Defaulting to 'false'. WARNING: 'odbdir' option not found. Defaulting to '/root/databases/neo4j_import'. Please make sure that there are no running servers on: '../graph.db' (Neo4j) and: '/root/databases/neo4j_import' (OrientDB) Initializing Neo4j...Done Initializing OrientDB...Done Importing Neo4j database: '../graph.db' into OrientDB database: '/root/databases/neo4j_import' Getting all Nodes from Neo4j and creating corresponding Vertices in OrientDB... 4 OrientDB Vertices have been created (100% done) Done Creating internal Indices on properties 'Neo4jNodeID' & 'Neo4jLabelList' on all OrientDB Vertices Classes... 4 OrientDB Indices have been created (100% done) Done Getting all Relationships from Neo4j and creating corresponding Edges in OrientDB... 2 OrientDB Edges have been created (100% done) Done Getting Constraints from Neo4j and creating corresponding ones in OrientDB... 0 OrientDB UNIQUE Indices have been created Done Getting Indices from Neo4j and creating corresponding ones in OrientDB... 0 OrientDB Indices have been created Done Import completed! Shutting down OrientDB...Done Shutting down Neo4j...Done =============== Import Summary: =============== - Found Neo4j Nodes : 4 -- With at least one Label : 4 --- With multiple Labels : 0 -- Without Labels : 0 - Imported OrientDB Vertices : 4 (100%) - Found Neo4j Relationships : 2 - Imported OrientDB Edges : 2 (100%) - Found Neo4j Constraints : 0 - Imported OrientDB Constraints (UNIQUE Indices created) : 0 - NOT UNIQUE Indices created due to failure in creating UNIQUE Indices : 0 - Found Neo4j (non-constraint) Indices : 0 - Imported OrientDB Indices : 0 - Additional internal Indices created : 4 - Total Import time: : 6 seconds -- Initialization time : 5 seconds -- Time to Import Nodes : 0 seconds (35.4 nodes/sec) -- Time to Import Relationships : 0 seconds (22.47 rels/sec) -- Time to Import Constraints and Indices : 0 seconds (0 indices/sec) -- Time to Create Internal Indices (on vertex properties 'Neo4jNodeID' & 'Neo4jLabelList') : 1 seconds (7.01 indices/sec)
覺得一切搞定,啓動OrientDB數據庫,並無看到新導入的數據庫... 再仔細查看發現沒有添加選項-odbdir(可是默認值應該是DB_HOME/databases/neo4j_import,不知道爲什麼沒有生效...),數據庫導入到其它路徑下,拷貝過來後能夠正常使用了。ui
(如圖,neo4j_import數據庫)spa