Neo Shell Guide

From NeoWiki

Jump to: navigation, search

NeoShell is a command-line shell for browsing the node space, much like how the Unix shell along with commands like cd, ls and pwd can be used to browse your local filesystem. NeoShell consists of two parts: a lightweight client that sends commands via RMI and a server that processes those commands and sends the result back to the client. It's a nice tool for development and debugging. This guide will show you how to get it going!

Contents

[edit] Configuring the shell server

There are two parts to installing the shell server.

  • First, you need to make sure that the shell jar file is on the classpath when you start up Neo.
    • If you don't use maven, go to http://neo4j.org/download and download the latest release of the shell-SOME_VERSION.jar file. Then add it to your -classpath command line switch, or to your ant-enabled lib folder, or right-click and add-to-build-path in Eclipse or however you add jar files to your classpath in your environment.
    • If you use maven (and have added the neo4j m2 repository to the <repositories>-tag in your pom as outlined in the Getting Started Guide): add the following to your pom.xml:
<dependency> 
	<groupId>org.neo4j</groupId>
	<artifactId>shell</artifactId>
	<version>SOME_VERSION</version>
</dependency>
  • Second, programmatically enable the remote shell server. You do this by invoking the enableRemoteShell() method in the EmbeddedNeo class as follows:
NeoService neo = new EmbeddedNeo( "neo" );
neo.enableRemoteShell();

There's also an enableRemoteShell() method that takes a map with configuration info, see NeoService's javadocs for more information.

[edit] Installing the shell client

The shell-SOME_VERSION jar file includes both the generic framework for the server and the client as well as an executable light-weight client. In order to execute it, run java -jar shell-SOME_VERSION.jar as follows:

$ java -jar shell-1.0-b6.jar 
NOTE: No port or RMI name specified, using default port 1337 and name 'shell'.
Welcome to NeoShell
Available commands: cd env exit export gsh ls man mkrel mv pwd rm rmel set quit
Use man <command> for info about each command.
neo-sh$ 

And you're off to go!

[edit] Running the shell client without an externally running neo service

If you'd just like to delve into a neo store without first starting up a NeoService and enabling its remote shell, you can let the shell start a neo service in the same JVM. Just do like this (slight more verbose syntax, which will be simplified prior to release 1.0).

$ java -cp neo-1.0-b6.jar:jta-spec1_0_1.jar:shell-1.0-b6.jar org.neo4j.util.shell.StartRemoteClient my-neo-store/
NOTE: Using local neo server at 'my-neo-store/'
Welcome to NeoShell
Available commands: cd env export gsh help jsh ls man mkrel mv pwd quit rm rmrel set
Use man <command> for info about each command.
neo-sh (0)$ 

[edit] How to use

NeoShell is modelled after Unix shells like bash that you use to walk around your local file system. It has some of the same commands, like cd and ls. When you first start a NeoShell (see instructions above), you will get a list of all the available commands. Use man <command> to get more info about a particular command. Some notes:

  • You have a current node and a "current path" (like a current working directory in bash) that you've walked so far. Check it with the pwd command.
  • Check info about the current node with the ls command. Please note that it will give an empty output if the current node has no properties or relationships (for example in the case of a brand new node space). ls can take a node id as argument as well as a number of filters. See man ls for more info.
  • You create new nodes by connecting them with relationships to the current node. For example, mkrel -t A_RELATIONSHIP_TYPE -d OUTGOING -c will create a new node (-c) and draw to it an OUTGOING relationship of type A_RELATIONSHIP_TYPE from the current node.
Personal tools