Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Phase 1: replicate users.

Using APOC Procedures on an Embedded Database from Java

Node Clone

I'm a novice to Neo4j, but have familiarity with graph databases. I've created a simple Java app that creates and queries an embedded Neo4j database. I'd like to use APOC graph analytics procedures to compute typical graph metrics, and be able to export the graph in JSON format to Gephi to visualize my database. I'm doing this with this small, example database before scaling to a larger database in a GCP environment.

I'm using:
-- iMac running macOS V10.15
-- Java 1.8
-- JetBrains IntelliJ IDE IntelliJ IDEA 2019.2.3 (Community Edition)
-- Neo4j V3.5.8
-- Neo4j Java driver V1.7.5
-- Neo4j Desktop app V1.2.1 (I don't use this because I haven't been able to get it to read the contents of my embedded database)

My head is spinning from having read blog posts, Neo4j Community questions & answers, StackOverflow questions and answers, and Neo4j documentation, all of which appear to my untrained eyes as not self-consistent. I'm really confused!

My simple questions are:
-- How do I call an APOC procedure from a Java app?
-- Do I need to install a Neo4j server to gain access to the APOC procedures from a Java app?
-- Do I need to include Maven dependencies to build my Java app?

Could you please either point me to documentation that answers my questions or some source code of a simple Java app that built a graph database and applied APOC procedures to its contents?

Thank you in advance for your help.
Ciro Pinto-Coelho


I wonder why you want to use embedded instead of a "normal" deployment.

Regardless on the "why" you do have 2 options for using APOC functionality in embedded. Both require to have


as a dependecy in your project.

Option 1: registering procs

Here you have to explicitly register all procedures and functions explicitly. You identify the class containing the stuff you need and use that snippet:
Once registered you can simply use these procedures/functions just like in server mode.

Option 2: use procedures directly from java code

Here you just do a new MyProcedureClass() and explicitly set all its field being annotated with @Context, e.g.

   Periodic p = new Periodic();
   p.db = <mygraphdbservice>;
   p..... = ...;

Stefan, thanks so much for your reply.

I chose an embedded deployment because my intention is develop the code on my iMac and then move it to a Google Cloud Platform environment to capitalize on the available machine learning, sentiment analysis, and chatbot services as well as to allow the processing to scale over time. If an embedded deployment isn't the right choice, I'm open to any suggestions you have about database deployment.

Thanks for the Maven dependency. Thanks also for describing the two options. I assume I use one of these options to access existing APOC procedures, is that correct?

Do I also use one of these options to access Neo4j graph algorithms described here? Do I need an additional Maven dependency to access the Neo4j graph algorithms?

Thanks in advance for your help, it is much appreciated.

Stefan, I included the Maven dependency you provided into the simple Java app I wrote to create a test database. Here is what I have in my POM file.




The app worked fine. When I added the Neo4j APOC dependency the app produced the following error message at runtime.

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/io/output/WriterOutputStream
	at apoc.util.ApocUrlStreamHandlerFactory.createURLStreamHandler(
	at java.util.ServiceLoader.parse(
	at java.util.ServiceLoader.access$200(
	at java.util.ServiceLoader$LazyIterator.hasNextService(
	at java.util.ServiceLoader$LazyIterator.hasNext(
	at java.util.ServiceLoader$1.hasNext(
	at java.util.Iterator.forEachRemaining(
	at java.util.Spliterators$IteratorSpliterator.forEachRemaining(
	at org.neo4j.configuration.LoadableConfig.allConfigClasses(
	at java.util.Optional.orElseGet(
	at org.neo4j.kernel.configuration.Config$
	at org.neo4j.kernel.configuration.Config.defaults(
	at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(
	at org.neo4j.graphdb.factory.GraphDatabaseFactory.newEmbeddedDatabase(
	at BaselineGitHubToGraphDb.main(
Caused by: java.lang.ClassNotFoundException:
	at java.lang.ClassLoader.loadClass(
	at sun.misc.Launcher$AppClassLoader.loadClass(
	at java.lang.ClassLoader.loadClass(
	... 30 more

Process finished with exit code 1

Lines 97 and 98 in my code (BaselineGitHubToGraphDb) are as follows:

        gdbFactory = new GraphDatabaseFactory();
        gdbService = gdbFactory.newEmbeddedDatabase(new File(gdbDirectory));

What am I missing?



do the trick?

Node Clone

Stefan, that dependency eliminated the error message, thanks.

I've rewritten my code to create a database in the Community Edition server instead of creating an embedded database. How do I call an APOC procedure to work on the data in this "normally deployed" database?

Thanks in advance for your help!

Not sure I understood your question correctly. I guess you're aware that you simply do a call apoc.<whatever>() to invoke a procedure.


We are using the inventory application with an embedded graph database.

APOC plugin jar apoc- is deployed in against neo4j Release 3.5.5. It is working fine on default graph database.
If same is connected with Embedded Database on bolt protocol 7070, unable to execute the APOC


APOC plugin jar apoc- is deployed in against neo4j Release 3.4.18. It is working fine on default graph database.
If same is connected with Embedded mode on bolt protocol 7070, unable to execute the APOC.
Please help to analyse.