Using the Neo4j Browser with Embedded Neo4j

· 1 min read

There are times when you have an application using Neo4j in embedded mode but also need to play around with the graph using the Neo4j web browser. Since the database can be accessed from at most one process at a time, trying to start up the Neo4j server when your embedded Neo4j application is running won’t work. The WrappingNeoServerBootstrapper, although deprecated, comes to the rescue. Here’s how to set it up.

Maven Dependencies

<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j</artifactId>
    <version>2.1.5</version>
</dependency>
<dependency>
    <groupId>org.neo4j.app</groupId>
    <artifactId>neo4j-server</artifactId>
    <version>2.1.5</version>
</dependency>
<dependency>
    <groupId>org.neo4j.app</groupId>
    <artifactId>neo4j-server</artifactId>
    <version>2.1.5</version>
    <classifier>static-web</classifier>
</dependency>

Start the WrappingNeoServerBootstrapper

public static void connectAndStartBootstrapper() {
    WrappingNeoServerBootstrapper neoServerBootstrapper;
    GraphDatabaseService db = new GraphDatabaseFactory()
            .newEmbeddedDatabaseBuilder("/path/to/db").newGraphDatabase();

    try {
        GraphDatabaseAPI api = (GraphDatabaseAPI) db;

        ServerConfigurator config = new ServerConfigurator(api);
        config.configuration()
            .addProperty(Configurator.WEBSERVER_ADDRESS_PROPERTY_KEY, "127.0.0.1");
        config.configuration()
            .addProperty(Configurator.WEBSERVER_PORT_PROPERTY_KEY, "7575");

        neoServerBootstrapper = new WrappingNeoServerBootstrapper(api, config);
        neoServerBootstrapper.start();
    catch(Exception e) {
       //handle appropriately
    }
}

Two things happen here- the GraphDatabaseService is ready to use in embedded mode, and the Neo4j web browser is available for use on http://127.0.0.1:7575/

You need not start them together but instead start and stop the WrappingNeoServerBootstrapper on demand, you just need to have a handle to the GraphDatabaseService.

Again, note that the WrappingNeoServerBootstrapper is deprecated. At the time of writing, this code works on 2.1.5 but does not offer any guarantees for future releases of Neo4j.

Luanne Misquitta

Engineering | Neo4j certification

Luanne Misquitta is an engineering leader with over 20 years of experience in start-ups and enterprises, both consulting and product oriented. She is widely recognised as one of the world's most experienced Neo4j consultants, having successfully implemented numerous projects in the field. Luanne has a track record of growing customer-focused, high-performing engineering teams and believes in lean principles driving engineering excellence.