David Prentiss
David Prentiss

Reputation: 558

What is wrong with my neo4j test setup? EmbeddedNeo4j.java, neo4j, maven

I started a project with maven using the "quickstart" archetype. I then changed my POM to include neo4j:

https://github.com/ENCE688R/msrcs/blob/master/pom.xml

I added:

https://github.com/neo4j/neo4j/blob/master/community/embedded-examples/src/main/java/org/neo4j/examples/EmbeddedNeo4j.java

and ran

mvn package

This works with no errors, but

java -cp target/msrcs-1.0-SNAPSHOT.jar org.neo4j.examples.EmbeddedNeo4j

Returns the Error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/neo4j/graphdb/RelationshipType

What am I missing? At this point I simply need to test that I can include and use neo4j.

Upvotes: 0

Views: 1730

Answers (3)

tstorms
tstorms

Reputation: 5001

I've started to work on some maven archetypes which could be a good starting point as well.

Upvotes: 1

Michael Hunger
Michael Hunger

Reputation: 41706

use

mvn exec:java -Dexec.mainClass=org.neo4j.examples.EmbeddedNeo4j

there is also mvn dependency:copy that copies all dependencies to target/dependencies

and there is the mvn appassembler plugin that allows you to generate startup shell scripts that include all your dependencies as a classpath.

And last but not least there is the maven assembly plugin mvn assembly:single which generates a single jar file that you can run java -jar my-jar-file.jar

Upvotes: 2

Matt Wielbut
Matt Wielbut

Reputation: 2692

You need to add the Neo4j dependencies to your classpath as well. At the moment you're only adding the source jar you created. If you look at this POM you'll see that Neo4J examples require many other dependencies.

Find the libs directory where the dependencies have been downloaded (this may be in your local .m2 maven repo) and add these jars to your classpath. You do not need to add each jar one-by-one as you can simply add a directory with wildcards - ex:

Windows:

java -cp "target/msrcs-1.0-SNAPSHOT.jar;lib/*" org.neo4j.examples.EmbeddedNeo4j

Mac/Unix:

java -cp "target/msrcs-1.0-SNAPSHOT.jar:lib/*" org.neo4j.examples.EmbeddedNeo4j

Upvotes: 1

Related Questions