1

我正在做一个大学项目,我必须在 neo4j 中导入海龟格式的本体。我在 github 上有一个代码,我尝试执行它。它适用于eclipse中的maven。运行代码后,我得到以下异常:

org.neo4j.graphdb.TransactionFailureException:等待数据库可用并允许新事务的超时。等了2m。阻塞原因1:高可用性成员状态未准备好。在 org.neo4j.kernel.impl.coreapi.CoreAPIAvailabilityGuard.assertDatabaseAvailable(CoreAPIAvailabilityGuard.java:57) 在 org.neo4j.kernel.impl.factory.ClassicCoreSPI.beginTransaction(ClassicCoreSPI.java:172) 在 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 完全陌生。有人可以帮忙吗?

4

0 回答 0