I am trying to import neo4j-cypher-dsl into an unmanaged server extension. I can start the extension but when I call the REST API method that uses DSL code I see the following error in the log:
javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: org/neo4j/cypherdsl/core/Cypher
at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:410) ~[jersey-container-servlet-core-2.34.jar:?]
...
Any idea why this is happening?
Michael here, author of the Neo4j Cypher-DSL.
let me just cross post my answer from our community site. It would be nice if you accept it.
This works just fine. Did you remember to package up the Cypher-DSL with your code? Cypher-DSL is not a module / library of the Neo4j database. It is distributed as a separate artifact. So if you want to use it inside an extension or plugin, you have to package it up. I usually suggest the
maven-assembly-plugin. An alternative is the Shade-Plugin.Here's a working example, first the
pom.xmlwith the dependencies. Notice how Neo4j core is in scope provided (as the extension is deployed into Neo4j, hence, the api is provided) and how Cypher-DSL is compile scope (Mavens) default:Notice the configuration of the assembler plugin. I use the predefined descriptorRef
jar-with-dependencies.The resulting JAR will contain the repackaged library. As I said, shading is another option (which can also rename packages).
The 3rd option would be packaging your code as you normally would (thin jar), add it as plugin to neo4j plus the cypher-dsl.jar.
Anyhow, here's the example code for reference:
when called, the result looks like this:
and the server prints the output I had in the code demonstrating that the message resource is not the cause of such a thing (
oops… At least one expressions to return is required.).