2

我在 Eclipse 中使用 maven 依赖项,并尝试使用 bolt 协议连接 neo4j 和 java。我在 MacOS 中运行应用程序。我正在使用 Eclipse 3 和 Java 版本 8 和 jre 1.8。这是我的 pom.xml **

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.neo4j</groupId>
  <artifactId>neo4j</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>neo4j</name>
  <url>http://maven.apache.org</url>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.neo4j.driver</groupId>
        <artifactId>neo4j-java-driver</artifactId>
        <version>1.2.1</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.neo4j</groupId>
      <artifactId>neo4j</artifactId>
      <version>3.1.4</version>
      <scope>provided</scope>
    </dependency>   
  </dependencies>
</project>

**

这是 .java 文件中调用的方法

void createDatabase()
    {
        GraphDatabaseService dfs = new GraphDatabaseFactory().newEmbeddedDatabase(dbPath);
        System.out.println("Database created!!");   
        Config noSSL = Config.build().withEncryptionLevel(Config.EncryptionLevel.NONE).toConfig();

        try(Driver dri = GraphDatabase.driver("bolt://localhost:7687", AuthTokens.basic( "neo4j", "hello" ), noSSL))
        {
            System.out.println("Database connected");

            Session session = dri.session();
            session.run("CREATE(a:Persona{name:{name}, title:{title}})", parameters("name","Aruna","title","Bhakt"));
            System.out.println("\n\t1.CREATED"); 

            StatementResult result =session.run("MATCH(a:Persona) WHERE a.name = {name}" + 
                                                    "RETURN a.name AS name, a.title AS title",
                                                    parameters("name","Aruna"));
            System.out.println("\n\t2.Match"); 

            while(result.hasNext())
            {
                Record record = result.next();
                System.out.println(record.get("title").asString() + " " + record.get("name").asString());

            }
            System.out.println("\n\t3.Found Record"); 

            session.close();
            dri.close();
        }
    }

运行应用程序后,我收到所有这些错误

Exception in thread "main" java.lang.RuntimeException: Error starting org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory, /Users/arundhatiwahane/Documents/Neo4j/default.graphdb
    at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.initFacade(GraphDatabaseFacadeFactory.java:199)
    at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.newFacade(GraphDatabaseFacadeFactory.java:130)
    at org.neo4j.graphdb.factory.GraphDatabaseFactory.newDatabase(GraphDatabaseFactory.java:101)
    at org.neo4j.graphdb.factory.GraphDatabaseFactory.lambda$createDatabaseCreator$0(GraphDatabaseFactory.java:89)
    at org.neo4j.graphdb.factory.GraphDatabaseFactory$$Lambda$1/1130478920.newDatabase(Unknown Source)
    at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:183)
    at org.neo4j.graphdb.factory.GraphDatabaseFactory.newEmbeddedDatabase(GraphDatabaseFactory.java:66)
    at com.sampledb.createDatabase(sampledb.java:41)
    at com.sampledb.main(sampledb.java:34)
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.internal.StoreLockerLifecycleAdapter@1b15e2a9' was successfully initialized, but failed to start. Please see attached cause exception.
    at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:443)
    at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:107)
    at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.initFacade(GraphDatabaseFacadeFactory.java:195)
    ... 8 more
Caused by: org.neo4j.kernel.StoreLockException: Store and its lock file has been locked by another process: /Users/arundhatiwahane/Documents/Neo4j/default.graphdb/store_lock. Please ensure no other process is using this database, and that the directory is writable (required even for read-only access)
    at org.neo4j.kernel.internal.StoreLocker.storeLockException(StoreLocker.java:94)
    at org.neo4j.kernel.internal.StoreLocker.checkLock(StoreLocker.java:80)
    at org.neo4j.kernel.internal.StoreLockerLifecycleAdapter.start(StoreLockerLifecycleAdapter.java:40)
    at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:433)
    ... 10 more

请帮助我找出我所有的错误。

4

1 回答 1

1

另一个进程正在锁定,杀死它

尝试

ps aux | grep neo4j

或者

ps aux | grep java

阅读您的异常描述

Caused by: org.neo4j.kernel.StoreLockException: Store and its lock file has been locked by another process: /Users/arundhatiwahane/Documents/Neo4j/default.graphdb/store_lock. Please ensure no other process is using this database, and that the directory is writable (required even for read-only access)

如果杀死进程没有解决你需要添加对目录的写权限

chmod -R 777 /Users/arundhatiwahane/Documents/Neo4j/
于 2017-09-17T22:44:18.977 回答