Getting Started In One Minute Guide
From NeoWiki
This is a compressed summary of the slightly more verbose Getting Started Guide. Please refer to the full guide if something here is unclear.
- If you don't use Maven: Download the Neo4j release and add the Neo4j kernel and JTA jars to your classpath.
- If you do use Maven: Check the Maven2 info here and add it to your
pom.xml.
- If you want some commonly used Neo4j components bundled right away, check out the Getting Started With Apoc guide before downloading/configuring anything.
- Declare your relationship types and start Neo4j (the complete code is here: One Minute Guide Complete Code):
public enum MyRelationshipTypes implements RelationshipType
{
KNOWS
}
...
GraphDatabaseService graphDb = new EmbeddedGraphDatabase( "var/base" );
- Create a small node space:
Node firstNode = graphDb.createNode(); Node secondNode = graphDb.createNode(); Relationship relationship = firstNode.createRelationshipTo( secondNode, MyRelationshipTypes.KNOWS ); firstNode.setProperty( "message", "Hello, " ); secondNode.setProperty( "message", "world!" ); relationship.setProperty( "message", "brave Neo4j " );
- Recall that Neo4j is fully transactional, so wrap everything in transactions:
Transaction tx = graphDb.beginTx();
try
{
// all Neo4j operations that work with the node space, for example:
// Node firstNode = graphDb.createNode();
// ... etc ...
tx.success();
}
finally
{
tx.finish();
graphDb.shutdown();
}
- Print the result and you're done:
System.out.print( firstNode.getProperty( "message" ) ); System.out.print( relationship.getProperty( "message" ) ); System.out.print( secondNode.getProperty( "message" ) );
Now, you can move on to more detailed information:
- the verbose version of this guide
- the complete code
- the javadocs at http://api.neo4j.org/current
- the basic code snippets PDF to learn the traverser framework
Finally, be sure to sign up on the mailing list.

