Neo4j Hello World Tutorial and webadmin

a 夏天 提交于 2019-12-13 04:38:48

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/17644095/neo4j-hello-world-tutorial-and-webadmin

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!