Including Neo4j in your project

This section describes how to embed Neo4j in your Java application.

After selecting the appropriate edition for your platform, you can embed Neo4j in your Java application by including the Neo4j library jars in your build. The following sections show how to do this by either altering the build path directly or by using dependency management.

1. Adding Neo4j to the build path

Get the Neo4j libraries from one of these sources:

Add the jar files to your project:

JDK tools

Append to -classpath

  • Right-click on the project and then go Build Path → Configure Build Path. In the dialog, choose Add External JARs, browse to the Neo4j lib/ directory and select all of the jar files.

  • Another option is to use User Libraries.

IntelliJ IDEA

See Libraries, Global Libraries, and the Configure Library dialog

  • Right-click on the Libraries node of the project, choose Add JAR/Folder, browse to the Neo4j lib/ directory and select all of the jar files.

  • You can also handle libraries from the project node, see Managing a Project’s Classpath.

2. Editions

The following table outlines the available editions and their names for use with dependency management tools.

Follow the links in the table for details on dependency configuration with Apache Maven, Apache Buildr, Apache Ivy, Groovy Grape, Grails, Scala SBT!
Table 1. Neo4j editions
Edition Dependency Description



a high performance, fully ACID transactional graph database



adding advanced monitoring, online backup and clustering

Note that the listed dependencies do not contain the implementation, but pulls it in transitively.

For information regarding licensing, see the Licensing Guide.

Javadocs can be downloaded packaged in jar files from Maven Central or read at Neo4j Javadocs.

3. Adding Neo4j as a dependency

You can either go with the top-level artifact from the table above or include the individual components directly. The examples included here use the top-level artifact approach.

Additional information for Enterprise Edition users.

The examples below are only valid Neo4j Community Edition.

To add Neo4j Enterprise Edition as a dependency, please get in contact with Neo4j Professional Services.

See Operations Manual → Introduction for details about the Community and Enterprise Editions.

3.1. Maven

Add the dependency to your project along the lines of the snippet below. This is usually done in the pom.xml file found in the root directory of the project.


Where the artifactId is found in the editions table.

3.2. Eclipse and Maven

For development in Eclipse, it is recommended to install the m2e plugin and let Maven manage the project build classpath instead, see above. This also adds the possibility to build your project both via the command line with Maven and have a working Eclipse setup for development.

3.3. Ivy

Make sure to resolve dependencies from Maven Central. You can use this configuration in your ivysettings.xml file:

  <settings defaultResolver="main"/>
    <chain name="main">
      <filesystem name="local">
        <artifact pattern="${ivy.settings.dir}/repository/[artifact]-[revision].[ext]" />
      <ibiblio name="maven_central" root="" m2compatible="true"/>

With that in place, add Neo4j by adding this to your 'ivy.xml' file:

  <dependency org="org.neo4j" name="neo4j" rev="4.3.2"/>

The name can be found in the editions table above.

3.4. Gradle

The example below shows an example Gradle build script for including the Neo4j libraries:

def neo4jVersion = "4.3.2"
apply plugin: 'java'
repositories {
dependencies {
   compile "org.neo4j:neo4j:${neo4jVersion}"

The coordinates (org.neo4j:neo4j in the example) are found in the editions table above.

4. Starting and stopping

To start the embedded DBMS you instantiate a org.neo4j.dbms.DatabaseManagementService and get theorg.neo4j.graphdb.GraphDatabaseService as follows:

managementService = new DatabaseManagementServiceBuilder( databaseDirectory ).build();
graphDb = managementService.database( DEFAULT_DATABASE_NAME );
registerShutdownHook( managementService );

If you are using the Enterprise Edition of Neo4j in embedded standalone mode, you have to create your database with the com.neo4j.dbms.api.EnterpriseDatabaseManagementServiceBuilder to enable the Enterprise Edition features.

If you are intending to operate embedded clusters, then you should use the com.neo4j.dbms.api.ClusterDatabaseManagementServiceBuilder with appropriate configuration. For maintainability purposes, you can define your embedded DBMS configuration in the neo4j.conf file as follows:

var managementService = new ClusterDatabaseManagementServiceBuilder( homeDirectory )
        .loadPropertiesFromFile( "/path/to/neo4j.conf" )

It is also possible to use the builder, and specify all the parameters programmatically:

var defaultAdvertised = new SocketAddress( "" );
var defaultListen = new SocketAddress( "" );

var initialMembers = List.of(
        new SocketAddress( "" ),
        new SocketAddress( "" ),
        new SocketAddress( "" )

var managementService = new ClusterDatabaseManagementServiceBuilder( homeDirectory )
        .setConfig( GraphDatabaseSettings.mode, CORE )
        .setConfig( GraphDatabaseSettings.default_advertised_address, defaultAdvertised )
        .setConfig( GraphDatabaseSettings.default_listen_address, defaultListen )
        .setConfig( CausalClusteringSettings.discovery_type, DiscoveryType.LIST )
        .setConfig( CausalClusteringSettings.initial_discovery_members, initialMembers )
        .setConfig( BoltConnector.enabled, true )
        .setConfig( HttpConnector.enabled, true )

It is important to carefully consider which services you want to enable, and on which ports and interfaces. If you do not require Bolt or HTTP then it can be better to leave those disabled.

The DatabaseManagementService and GraphDatabaseService instances can be shared among multiple threads. Note however, that you cannot create multiple services pointing to the same database.

To stop the database, call the shutdown() method:


To make sure Neo4j is shut down properly, add a shutdown hook:

private static void registerShutdownHook( final DatabaseManagementService managementService )
    // Registers a shutdown hook for the Neo4j instance so that it
    // shuts down nicely when the VM exits (even if you "Ctrl-C" the
    // running application).
    Runtime.getRuntime().addShutdownHook( new Thread()
        public void run()
    } );

4.1. Starting an embedded database with configuration settings

To start Neo4j with configuration settings, a Neo4j properties file can be loaded like this:

DatabaseManagementService managementService = new DatabaseManagementServiceBuilder( directory )
                                                    .loadPropertiesFromFile( pathToConfig + "neo4j.conf" ).build();
GraphDatabaseService graphDb = managementService.database( DEFAULT_DATABASE_NAME );

Configuration settings can also be applied programmatically, like so:

DatabaseManagementService managementService = new DatabaseManagementServiceBuilder( directory)
                        .setConfig( GraphDatabaseSettings.pagecache_memory, "512M" )
                        .setConfig( GraphDatabaseSettings.transaction_timeout, Duration.ofSeconds( 60 ) )
                        .setConfig( GraphDatabaseSettings.preallocate_logical_logs, true ).build();
GraphDatabaseService graphDb = managementService.database( DEFAULT_DATABASE_NAME );

4.2. Starting an embedded read-only instance

If you want a read-only view of the database, create an instance this way:

managementService = new DatabaseManagementServiceBuilder( dir ).setConfig( GraphDatabaseSettings.read_only_database_default, true ).build();
graphDb = managementService.database( DEFAULT_DATABASE_NAME );

Obviously, the database has to already exist in this case.

Concurrent access to the same database files by multiple (read-only or write) instances is not supported.