I tried the following basic example about executing Cypher queries from Java in embedded mode as is, but it shows the errors below:
Code:
package test;
import org.neo4j.cypher.javacompat.ExecutionEngine;
import org.neo4j.cypher.javacompat.ExecutionResult;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
public class Test {
public static void main(String[] args) {
GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase("D:/MI/Tools/neo4j-community-1.9.M02/test2");
// add some data first, keep id of node so we can refer to it
long id;
Transaction tx = db.beginTx();
try {
Node refNode = db.createNode();
id = refNode.getId();
refNode.setProperty("name", "reference node");
tx.success();
} finally {
tx.finish();
}
// let's execute a query now
ExecutionEngine engine = new ExecutionEngine(db);
ExecutionResult result = engine.execute("start n=node(" + id + ") return n, n.name");
System.out.println(result.toString());
}
}
Output:
Exception in thread "main" java.lang.NoClassDefFoundError: com/googlecode/concurrentlinkedhashmap/ConcurrentLinkedHashMap$Builder
at org.neo4j.cypher.internal.LRUCache.<init>(LRUCache.scala:30)
at org.neo4j.cypher.ExecutionEngine$$anon$1.<init>(ExecutionEngine.scala:91)
at org.neo4j.cypher.ExecutionEngine.<init>(ExecutionEngine.scala:91)
at org.neo4j.cypher.javacompat.ExecutionEngine.<init>(ExecutionEngine.java:54)
at org.neo4j.cypher.javacompat.ExecutionEngine.<init>(ExecutionEngine.java:44)
at test.Test.main(Test.java:27)
Caused by: java.lang.ClassNotFoundException: com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap$Builder
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 6 more
Java Result: 1
BUILD SUCCESSFUL (total time: 5 seconds)
Is there any problem in the code?
(I use neo4j-community-1.9.M02 and NetBeans IDE 7.2.1)
Thanks.
The problem disappeared after adding the following Java library to the project
http://concurrentlinkedhashmap.googlecode.com/files/concurrentlinkedhashmap-lru-1.3.1.jar