Showing results for 
Search instead for 
Did you mean: 

java.lang.ClassNotFoundException when running embedded Neo4j example


I only used Neo4j through Cypher querys in the past, now I need to write code for a Neo4j graphdatabase for my bachelor thesis. I set up a Maven project in Eclipse following these instructions: How to set up a maven project with Neo4j in Eclipse and Including Neo4j in your project

To get familiar with using embedded Neo4j I tried to run this example: Hello World- Java Reference
I also found the code on Github and copied it, so this cannot be a problem in the code.

Code on GitHub

In the beginning I declare an enum for the different relationship types which I then use in the method createDb(). In the main method I create a new Object from the class and run the method createDb().

private enum RelTypes implements RelationshipType{

void createDb() throws IOException{
            ...//database created
            try (Transaction tx = graphDb.beginTx()){    
                firstNode = tx.createNode();
                secondNode = tx.createNode();
                relationship = firstNode.createRelationshipTo(secondNode, RelTypes.KNOWS); 

public static void main(String [] args) throws IOException{
         Setup hello = new Setup();

That's when I get the java.lang.ClassNotFoundExecption.

Exception in thread "main" java.lang.NoClassDefFoundError: bachelorarbeit/masymos_44/Setup$RelTypes
	at bachelorarbeit.masymos_44.Setup.createDb(
	at bachelorarbeit.masymos_44.Setup.main(
Caused by: java.lang.ClassNotFoundException: bachelorarbeit.masymos_44.Setup$RelTypes
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(
	at java.base/java.lang.ClassLoader.loadClass(
	... 2 more

I use Neo4j version 4.4.4 and the JDK 11.0.14 with a SE 1.7.
I already tried to clean, refresh and update the project and checked the classpaths. I also deleted and reinstalled Eclipse and created the project again but I still get the same error. The same error also occurs when I try to use other classes after I created the database. Eclipse doesn't show any errors or warnings in the project.

Does anyone knows how to fix this error? Do I do something wrong when setting up the project or do I maybe miss any maven dependencies or .jar files?

I use Maven 4.0.0. My pom.xml looks like this:



Any help is appreciated. Thanks a lot,


Graph Buddy

In simple java this error means that the new enum class should be in class path.
May be this will give you an insight into what you are trying to accomplish.
Many thanks

Anyway welcome to Neo4j community
-Mr. Sameer Gijare


thank you for your answer. Funny enough, I just added the first line in the main method in my code and suddenly it worked.

public static void main(String [] args) throws IOException{
    	RelTypes rt = RelTypes.KNOWS;
    	Setup hello = new Setup();

Do you know why?
I will do a larger project with neosemantics where I will need to declare new objects from different classes inside the database but I always got the same error as above.

Thanks, Jana