Reputation: 116
I'm learning Neo4j
via their tutorials.
I've got the Hello World
tutorial working, but I'm wondering how to view the graph in the webadmin on localhost. I assume the first step is not to call removeData() and shutDown(), but just doing that isn't accomplishing it.
Basically, how can I run the the Hello World
tutorial and then view/query it through webadmin?
Upvotes: 0
Views: 1381
Reputation: 1518
If what you want is to access webadmin after your project stopped, like Luanne said, calling shutdown()
will not erase anything, so you can go to your-neo4j-installation-path/conf/neo4j-server.properties
and change the org.neo4j.server.database.location
property to the same path you used in your code.
From the link you gave, that would be the path you put here:
graphDb = new GraphDatabaseFactory().newEmbeddedDatabase( DB_PATH );
After that you call your-neo4j-installation-path/bin/neo4j start
(or neo4j.bat if you're using windows) and it should work.
But if what you want is to make webadmin available to you while your project is running, with the embedded server, then here is what you should do.
First, to make neo4j embedded work, you should put all the jars in your-neo4j-installation-path/lib/
in the buildpath of your project, right?
To make webadmin available while the embedded database is in use, you should also put all the jars in your-neo4j-installation-path/system/lib/
in the buildpath of your project.
Then you will create the GraphDatabaseService as usual.
GraphDatabaseService graphDb;
graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
Then you will make an instance of the WrappingNeoServerBootstrapper class.
WrappingNeoServerBootstrapper srv = new WrappingNeoServerBootstrapper((GraphDatabaseAPI) graphdb);
(The constructor receives a GraphDatabaseAPI, which is now deprecated, so we make a GraphDatabaseService and put a cast when passing it to WrappingNeoServerBoorstrapper()
)
Last but not least, you use the method start()
.
srv.start();
And voilá.
If you want it to stop, just call srv.stop()
I suggest you add a registerShutdownHook()
method (like this tutorial suggests) and put the stop()
method in there.
private static void registerShutdownHook( final GraphDatabaseService graphDb )
{
// 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()
{
@Override
public void run()
{
srv.stop();
graphDb.shutdown();
}
} );
}
And that's it.
Upvotes: 0
Reputation: 19373
Calling shutdown won't destroy your data. Can you share your code? Also make sure your Neo4j server points to the same database used in your code i.e. DB_PATH from
graphDb = new GraphDatabaseFactory().newEmbeddedDatabase( DB_PATH )
You can check this property org.neo4j.server.database.location in the file neo4j-server.properties found in the conf directory of your neo4j installation.
Upvotes: 1