使用Maven,我添加了neo4j:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.bureau13</groupId>
<artifactId>rpglib</artifactId>
<packaging>war</packaging>
<version>0.0.1</version>
<name>rpglib Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>2.1.5</version>
</dependency>
</dependencies>
<build>
<finalName>rpglib</finalName>
</build>
</project>
我写了以下测试:
public class Neo4JTest {
GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase( "rpglib" );
ExecutionEngine engine = new ExecutionEngine( graphDb, null );
Node createNode = graphDb.createNode();
@Test
public void testBootup() {
try {
Transaction tx = graphDb.beginTx();
createNode.setProperty("name", "Sword of Strength");
} finally {
}
}
@Test
public void testFind() {
try {
Transaction tx = graphDb.beginTx();
Node foundNode = graphDb.getNodeById( createNode.getId() );
} finally {
}
}
}
我在两个测试中都得到以下异常:
java.lang.NoClassDefFoundError: org/neo4j/cypher/internal/compiler/v2_0/CypherCompiler
at org.neo4j.cypher.internal.CypherCompiler.<init>(CypherCompiler.scala:61)
at org.neo4j.cypher.ExecutionEngine.createCompiler(ExecutionEngine.scala:150)
at org.neo4j.cypher.ExecutionEngine.<init>(ExecutionEngine.scala:48)
at org.rpglib.persistence.Neo4JTest.<init>(Neo4JTest.java:13)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:195)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:244)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:241)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.ClassNotFoundException: org.neo4j.cypher.internal.compiler.v2_0.CypherCompiler
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 26 more
违规类是org / neo4j / cypher / internal / compiler / v2_0 / CypherCompiler。
然而,在Eclipse中,我可以在我的Maven依赖项中看到它。
我还可以看到我有三个Cypher编译器依赖项:
由于它在v2_0路径中寻找CypherCompiler,我排除了没有该路径的编译器jar,只保留了第二个..但是当我这样做时,我获得了ClassNotFoundExceptions那些罐子里的课程。
有3个CypherCompiler类,但它们都有不同的包:
我不知所措。罐子有不同的包装路径,所以应该没有问题,对吧?
答案 0 :(得分:0)
从eclipse切换到Intellij IDEA为我解决了这个问题。我仍然不知道原因是什么。