Kevin Krumwiede
Kevin Krumwiede

Reputation: 10308

Which jars are required for embedded Neo4j?

I'm looking for an updated answer to this question. Previously, a minimal Neo4j "Hello World" app required two jars. Now it apparently requires some other jars, but I don't know which ones.

If I include neo4j-kernel-2.1.2 and geronimo-jta_1.1_spec-1.1.1 as suggested in that other question, I get this error:

java.lang.ClassNotFoundException: org.neo4j.collection.primitive.PrimitiveLongIterator
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:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

If I add neo4j-primitive-collections-2.1.2, I then get an error with this root cause:

Caused by: java.lang.IllegalArgumentException: No schema index provider org.neo4j.kernel.api.index.SchemaIndexProvider found.

Answers on this question suggest I need neo4j-lucene-index. When I add that jar, I get this error:

Caused by: java.lang.ClassNotFoundException: org.apache.lucene.store.Directory
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:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

Finally, when I add lucene-core, I get this error:

Caused by: java.lang.ClassNotFoundException: org.apache.lucene.document.Fieldable
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:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

What do I need to add to get past that?

Upvotes: 2

Views: 2842

Answers (2)

Kevin Krumwiede
Kevin Krumwiede

Reputation: 10308

I believe I've found the minimal set of dependencies for Neo4j 2.x. I was originally trying to use lucene-core-4.9.0, but the org.apache.lucene.document.Fieldable interface was removed from that library sometime after version 3.6.2. The minimal set of jars is thus:

neo4j-kernel (2.1.2)
neo4j-primitive-collections (2.1.2)
neo4j-lucene-index (2.1.2)
lucene-core (3.6.2)
jta (1.1)

These weigh in at about 4.5 MB, which is larger than I'd like, but I guess I can live with it. I've also been told that neo4j-lucene-index (which is what requires lucene-core) is not strictly required. Like jta, it's actually only one possible implementation of a required interface. But I don't know of any other implementation.

Upvotes: 5

Stefan Armbruster
Stefan Armbruster

Reputation: 39925

As the other answer correctly mention the most easy way is use a build tool featuring a dependency manager. Most widely these days used are Maven and Gradle. Both use Maven Central repository by default to pull dependencies and transitive dependencies.

Depending whether your embedded application uses cypher or not you should add the following dependencies your pom.xml:

<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-lucene-index</artifactId>
    <version>2.1.2</version>
</dependency>

or (when cypher is used):

<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-cypher</artifactId>
    <version>2.1.2</version>
</dependency>

Both of them transitively include all necessary libraries.

Upvotes: 4

Related Questions