18.4. Using the server (including web administration) with an embedded database

18.4.1. Getting the libraries
18.4.2. Starting the Server from Java
18.4.3. Providing custom configuration

Even if you are using the Neo4j Java API directly, for instance via EmbeddedGraphDatabase or HighlyAvailableGraphDatabase, you can still use the features the server provides.

18.4.1. Getting the libraries

From the Neo4j Server installation

To run the server all the libraries you need are in the system/lib/ directory of the download package. For further instructions, see Section 4.1, “Include Neo4j in your project”. The only difference to the embedded setup is that system/lib/ should be added as well, not only the lib/ directory.

Via Maven

For users of dependency management, an example for Apache Maven follows. Note that the web resources are in a different artifact.

Maven pom.xml snippet. 

<dependencies>
  <dependency>
    <groupId>org.neo4j.app</groupId>
    <artifactId>neo4j-server</artifactId>
    <version>${neo4j-version}</version>
  </dependency>
  <dependency>
    <groupId>org.neo4j.app</groupId>
    <artifactId>neo4j-server</artifactId>
    <classifier>static-web</classifier>
    <version>${neo4j-version}</version>
  </dependency>
</dependencies>
<repositories>
  <repository>
    <id>neo4j-release-repository</id>
    <name>Neo4j Maven 2 release repository</name>
    <url>http://m2.neo4j.org/releases</url>
    <releases>
      <enabled>true</enabled>
    </releases>
    <snapshots>
      <enabled>false</enabled>
    </snapshots>
  </repository>
</repositories>

Where ${neo4j-version} is the intended version.

Via Scala SBT / Ivy

In order to pull in the dependencys with SBT and configure the underlying Ivy dependency manager, you can use a setup like the following in your build.sbt:

organization := "your.org"

name := "your.name"

version := "your.version"

/** Deps for Embedding the Neo4j Admin server - works around: http://neo4j.com/forums/#nabble-td3477583 */
libraryDependencies ++= Seq(
   "org.neo4j.app" % "neo4j-server" % "{neo4j-version}",
   "org.neo4j.app" % "neo4j-server" % "{neo4j-version}" classifier "static-web"
      from "http://m2.neo4j.org/releases/org/neo4j/app/neo4j-server/1.5/neo4j-server-1.5-static-web.jar", "com.sun.jersey" % "jersey-core" % "1.9"
)

/** Repos for Neo4j Admin server dep */
resolvers ++= Seq(
  "tinkerprop" at "http://tinkerpop.com/maven2",
  "neo4j-public-repository" at "http://m2.neo4j.org/releases"
)

Where ${neo4j-version} is the intended version.

18.4.2. Starting the Server from Java

The Neo4j server exposes a class called WrappingNeoServerBootstrapper, which is capable of starting a Neo4j server in the same process as your application. It uses an AbstractGraphDatabase instance that you provide.

This gives your application, among other things, the REST API, statistics gathering and the web administration interface that comes with the server.

Usage example. 

AbstractGraphDatabase graphdb = getGraphDb();
WrappingNeoServerBootstrapper srv;
srv = new WrappingNeoServerBootstrapper( graphdb );
srv.start();
// The server is now running
// until we stop it:
srv.stop();

Once you have the server up and running, see Chapter 27, Web Administration and Chapter 19, REST API for how to use it!

18.4.3. Providing custom configuration

You can modify the server settings programmatically and, within reason, the same settings are available to you here as those outlined in Section 18.2, “Server Configuration”.

The settings that are not available (or rather, that are ignored) are those that concern the underlying database, such as database location and database configuration path.

Custom configuration example. 

// let the database accept remote neo4j-shell connections
GraphDatabaseAPI graphdb = (GraphDatabaseAPI) new GraphDatabaseFactory().newEmbeddedDatabaseBuilder( "target/configDb" ).setConfig( ShellSettings.remote_shell_enabled, GraphDatabaseSetting.TRUE ).newGraphDatabase();
EmbeddedServerConfigurator config;
config = new EmbeddedServerConfigurator( graphdb );
// let the server endpoint be on a custom port
config.configuration().setProperty(
        Configurator.WEBSERVER_PORT_PROPERTY_KEY, 7575 );

WrappingNeoServerBootstrapper srv;
srv = new WrappingNeoServerBootstrapper( graphdb, config );
srv.start();