我刚开始使用Neo4j Java API。我之前从未使用过Maven(因为我发现将jar添加到项目中更简单)并且很遗憾我不理解我的代码抛出的错误。
我在OS X 10.11上的Eclipse中编码,在Eclipse中我使用M2Eclipse(对于像这样的Maven项目)并使用Neo4j Community Edition V 3.0.3设置我的Neo4j数据库。
我真的不明白这个错误。似乎某个地方缺少一个班级,但我不知道为什么。
这是我的代码(正如我所说,我只想试用API)
public static void main(String[] args) {
GraphDatabaseFactory f = new GraphDatabaseFactory();
GraphDatabaseService db = f.newEmbeddedDatabase(new File("/Users/Me/Documents/Neo4j/default.graphdb"));
try ( Transaction t = db.beginTx() )
{
Node johannesNode = db.createNode(KnowledgeComposer.NodeType.PERSON);
johannesNode.setProperty("Name", "Johannes");
johannesNode.setProperty("Age", 17);
johannesNode.setProperty("Class", "Q1");
Node stuteNode = db.createNode(KnowledgeComposer.NodeType.PERSON);
stuteNode.setProperty("Name", "Barbara");
Node annaNode = db.createNode(KnowledgeComposer.NodeType.PERSON);
annaNode.setProperty("Name", "Anna");
annaNode.setProperty("Age", 17);
annaNode.setProperty("Class", "Q1");
Node davidNode = db.createNode(KnowledgeComposer.NodeType.PERSON);
davidNode.setProperty("Name", "David");
davidNode.setProperty("Age", 16);
davidNode.setProperty("Class", "EF");
Node stuteLK = db.createNode(KnowledgeComposer.NodeType.COURSE);
stuteLK.setProperty("Name", "English LK");
stuteLK.setProperty("Room", "1.11");
stuteLK.setProperty("Started", 2015);
stuteLK.setProperty("Ends", 2017);
Relationship johannesLKRel = johannesNode.createRelationshipTo(stuteLK, RelType.BELONGS_TO);
johannesLKRel.setProperty("Function", "Student");
Relationship davidLKRel = davidNode.createRelationshipTo(stuteLK, RelType.BELONGS_TO);
davidLKRel.setProperty("Function", "Student");
Relationship stuteLKRel = stuteNode.createRelationshipTo(stuteLK, RelType.BELONGS_TO);
stuteLKRel.setProperty("Function", "Teacher");
annaNode.createRelationshipTo(johannesNode, RelType.KNOWS);
johannesNode.createRelationshipTo(stuteNode, RelType.KNOWS);
johannesNode.createRelationshipTo(davidNode, RelType.KNOWS);
davidNode.createRelationshipTo(johannesNode, RelType.KNOWS);
t.success();
}
db.shutdown();
}
这是它抛出的错误
Exception in thread "main" java.lang.RuntimeException: Error starting org.neo4j.kernel.impl.factory.CommunityFacadeFactory, /Users/Me/Documents/Neo4j/default.graphdb
at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.newFacade(GraphDatabaseFacadeFactory.java:144)
at org.neo4j.kernel.impl.factory.CommunityFacadeFactory.newFacade(CommunityFacadeFactory.java:40)
at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.newFacade(GraphDatabaseFacadeFactory.java:108)
at org.neo4j.graphdb.factory.GraphDatabaseFactory.newDatabase(GraphDatabaseFactory.java:100)
at org.neo4j.graphdb.factory.GraphDatabaseFactory.lambda$createDatabaseCreator$194(GraphDatabaseFactory.java:89)
at org.neo4j.graphdb.factory.GraphDatabaseFactory$$Lambda$1/636718812.newDatabase(Unknown Source)
at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:183)
at org.neo4j.graphdb.factory.GraphDatabaseFactory.newEmbeddedDatabase(GraphDatabaseFactory.java:65)
at de.codej.knowledgecomposer.main.KnowledgeComposer.main(KnowledgeComposer.java:27)
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.extension.KernelExtensions@719b03d4' failed to initialize. Please see attached cause exception.
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.init(LifeSupport.java:416)
at org.neo4j.kernel.lifecycle.LifeSupport.init(LifeSupport.java:62)
at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:98)
at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.newFacade(GraphDatabaseFacadeFactory.java:140)
... 8 more
Caused by: java.lang.NoClassDefFoundError: org/apache/lucene/store/Directory
at org.neo4j.kernel.api.impl.index.storage.DirectoryFactory.<clinit>(DirectoryFactory.java:55)
at org.neo4j.kernel.api.impl.index.LuceneKernelExtensions.lambda$directoryFactory$1(LuceneKernelExtensions.java:30)
at org.neo4j.kernel.api.impl.index.LuceneKernelExtensions$$Lambda$54/888350457.apply(Unknown Source)
at org.neo4j.io.fs.DefaultFileSystemAbstraction.getOrCreateThirdPartyFileSystem(DefaultFileSystemAbstraction.java:187)
at org.neo4j.kernel.api.impl.index.LuceneKernelExtensions.directoryFactory(LuceneKernelExtensions.java:29)
at org.neo4j.kernel.api.impl.labelscan.LuceneLabelScanStoreExtension.newInstance(LuceneLabelScanStoreExtension.java:77)
at org.neo4j.kernel.api.impl.labelscan.LuceneLabelScanStoreExtension.newInstance(LuceneLabelScanStoreExtension.java:40)
at org.neo4j.kernel.extension.KernelExtensions.init(KernelExtensions.java:69)
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.init(LifeSupport.java:406)
... 11 more
Caused by: java.lang.ClassNotFoundException: org.apache.lucene.store.Directory
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 20 more
提前谢谢!
编辑:
我的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>de.codej</groupId>
<artifactId>KnowledgeComposer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>KnowledgeComposer</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<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.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
答案 0 :(得分:0)
这确实是一个缺少类的例外。当您收到类似错误时,您可以谷歌查找所需的依赖项。通常,https://mvnrepository.com/的搜索结果将包含必要的信息。在您的情况下,如果您在pom.xml中添加以下行(找到here),您就会错过org.lucene依赖项,这可以满足:
<dependencies>
....
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-cypher</artifactId>
<version>3.0.1</version>
</dependency>
....
</dependencies>