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
publicstaticvoidconnectAndStartBootstrapper(){WrappingNeoServerBootstrapperneoServerBootstrapperGraphDatabaseServicedb=newGraphDatabaseFactory().newEmbeddedDatabaseBuilder("/path/to/db").newGraphDatabasetry{GraphDatabaseAPIapi=(GraphDatabaseAPI)dbServerConfiguratorconfig=newServerConfigurator(apiconfig.configuration().addProperty(Configurator.WEBSERVER_ADDRESS_PROPERTY_KEY,"127.0.0.1"config.configuration().addProperty(Configurator.WEBSERVER_PORT_PROPERTY_KEY,"7575"neoServerBootstrapper=newWrappingNeoServerBootstrapper(api,configneoServerBootstrapper.startcatch(Exceptione){//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.