我正在做一个大学项目,我必须在neo4j中导入乌龟格式的本体。我在github上得到了一个代码,我试着执行它。它适用于日食中的maven。运行代码后,我得到以下异常:
org.neo4j.graphdb.TransactionFailureException:超时等待数据库变为可用并允许新事务。等了2米。阻止的1个原因:高可用性成员状态未准备好。 at org.neo4j.kernel.impl.coreapi.CoreAPIAvailabilityGuard.assertDatabaseAvailable(CoreAPIAvailabilityGuard.java:57) 在org.neo4j.kernel.impl.factory.ClassicCoreSPI.beginTransaction(ClassicCoreSPI.java:172) at org.neo4j.kernel.impl.factory.GraphDatabaseFacade.beginTransactionInternal(GraphDatabaseFacade.java:575) at org.neo4j.kernel.impl.factory.GraphDatabaseFacade.beginTransaction(GraphDatabaseFacade.java:380) at org.neo4j.kernel.impl.factory.GraphDatabaseFacade.beginTx(GraphDatabaseFacade.java:368) 在org.neo4j.abcd.Executable.main(Executable.java:42)
这是代码:
package org.neo4j.abcd;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.util.HashMap;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseBuilder;
import org.neo4j.graphdb.factory.HighlyAvailableGraphDatabaseFactory;
import org.openrdf.rio.RDFParser;
import org.openrdf.rio.turtle.TurtleParser;
public class Executable {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
if(args.length!=1){
throw new Exception("Provide a file path as a parameter!");
}
Transaction tx = null;
File file = new File(args[0]);
File fp=new File("db.local");
if(!file.canRead())
throw new Exception("Can't read the file.");
HashMap<String, String> settings = new HashMap<String, String>();
settings.put("org.neo4j.server.database.mode", "HA");
GraphDatabaseService db = new HighlyAvailableGraphDatabaseFactory()
.newEmbeddedDatabaseBuilder(fp).loadPropertiesFromFile("neo4j.properties").setConfig(settings)
.newGraphDatabase();
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
RDFParser rdfParser = new TurtleParser();
try{
tx = db.beginTx();
Neo4jHandler handler = new Neo4jHandler(db);
rdfParser.setRDFHandler(handler);
rdfParser.parse(bis, file.toURI().toString());
System.out.println(handler.getCountedStatements());
tx.success();
}
catch(Exception e){
// Mark Transaction as failed
if (tx != null)
{
tx.failure();
}
e.printStackTrace();
}
finally
{
// Close Transaction
if (tx != null)
{
tx.close();
}
}
}
}
我对neo4j和maven完全不熟悉。 有人可以帮忙解决这个问题。