Like @chrylis pointed out, your error seems to be the issue that you don’t have the required jars and hence the errors. Now from your comments, I see that you are having difficulties with understanding maven and dependencies. So here's a simple guide that I made for you.
[Understand that this is NOT a one stop guide and this program might
not run out of the box. Its running for me at the moment but it
depends on many things including what version of neo4j you are running
and several other configuration factors. Nonetheless, this should be sufficient to get
you started. ]
You need to have maven installed on your system. There are few cool tutorials on maven. One is here. https://www.youtube.com/watch?v=al7bRZzz4oU&list=PL92E89440B7BFD0F6
But like me if you want a faster way, the new Eclipse Luna comes with maven installed for it. So download the new eclipse luna if you wish. Even with older eclipse versions you can go to marketplace and install the maven for eclipse.
Once done, make a maven quickstart project and replace your pom.xml file with the one below.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>rash.experiments</groupId>
<artifactId>neo4j</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>neo4j</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>neo4j-release-repository</id>
<name>Neo4j Maven 2 release repository</name>
<url>http://m2.neo4j.org/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-rest-graphdb</artifactId>
<version>2.0.1</version>
</dependency>
</dependencies>
</project>
I assume that you have neo4j setup. I will not go into major details, but in the neo4j directory, under conf, in neo4j-server.properties file, you need to uncomment the line
org.neo4j.server.webserver.address = 0.0.0.0
This basically lets you access this server from your java code that you will run from another machine. After making this change, make sure that you restart your server and that its accessible to other machines. To test you can run http://ip.address.of.this.machine:7474 and the web portal that comes with neo4j should open up.
Note: I assume that you have some data in your database. This is
required otherwise the program will fail. If you need some sample
data, go to http://ip_address_of_your_neo4j_web_server:7474/ and load the
movie graph database that comes with the installation.
Now lets code. Make this class in the project that you created above.
package rash.experiments.neo4j;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import org.neo4j.rest.graphdb.RestAPI;
import org.neo4j.rest.graphdb.RestAPIFacade;
import org.neo4j.rest.graphdb.query.QueryEngine;
import org.neo4j.rest.graphdb.query.RestCypherQueryEngine;
import org.neo4j.rest.graphdb.util.QueryResult;
public class Neo4JRestTest
{
public static void main(String args[])
{
RestAPI graphDb = new RestAPIFacade("http://192.168.1.8:7474/db/data/");
QueryEngine engine = new RestCypherQueryEngine(graphDb);
QueryResult<Map<String, Object>> result = engine.query("start n=node(*) return count(n) as total", Collections.EMPTY_MAP);
Iterator<Map<String, Object>> iterator = result.iterator();
if (iterator.hasNext())
{
Map<String, Object> row = iterator.next();
System.out.print("Total nodes: " + row.get("total"));
}
}
}
Now to run, you need to build your project first because maven will not download any of your jars that your specified in pom.xml until you have run it. So if you installed maven, go to the directory where you have your pom.xml and then write in the command line mvn clean package. This command will run and install all the dependencies and then will run your program. Since there are no test cases to run, it will succeed. But our goal was not to run any test cases. It was to download all the jars. Now that you have everything, you can run the java code and you will see your end results.
In case you are using maven from eclispe, then you right click your project and then do run as -> maven build. For the first time, a dialog will appear. Just write package in it and press enter. It will do the same things as above and bring all the jars. Then execute the program like you would above.
In case you get errors such as "No endpoint" or "error reading JSON", then understand that somehow the REST API is not able to read your graph.
check the property inside neo4j-server.properties. It should be whatever you are mentioning in your URL.
org.neo4j.server.webadmin.data.uri = /db/data/
ClassNotFoundException
is a pretty standard Java issue. – chrylis -cautiouslyoptimistic-