Home » Java » Enterprise Java » Using the Neo4j browser with Embedded Neo4j

About Luanne Misquitta

Using the Neo4j browser with Embedded Neo4j

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.
 
 
 
 
 

1. Make sure you have these 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>

2. Start the WrappingNeoServerBootstrapper

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

  
    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.

Reference: Using the Neo4j browser with Embedded Neo4j from our JCG partner Luanne Misquitta at the Thought Bytes blog.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

 

and many more ....

 

Receive Java & Developer job alerts in your Area

I have read and agree to the terms & conditions

 

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Ankit
Ankit
7 years ago

Server is up at 7575 but when i query then it is just loading,i am getting no data.

I am getting this script error

TypeError: Argument 1 of Window.getComputedStyle does not implement interface Element.

…elector),!match||!match[1]&&context)return!context||context.jquery?(context||roo…

and also data is not coming from server,getting error 302 and 204.