neo4j-contrib / spatial

Neo4j Spatial is a library of utilities for Neo4j that faciliates the enabling of spatial operations on data. In particular you can add spatial indexes to already located data, and perform spatial operations on the data like searching for data within specified regions or within a specified distance of a point of interest. In addition classes are provided to expose the data to geotools and thereby to geotools enabled applications like geoserver and uDig.
http://neo4j-contrib.github.io/spatial
Other
778 stars 192 forks source link

NoClassDefFoundError and NoSuchMethodError #293

Closed m007 closed 7 years ago

m007 commented 7 years ago

I'm currently running the official Neo4j 3.1.0 from dockerhub.com as base for a docker image where I use the latest version of this repository to build the *server-plugin.jar to the plugins directory.

Running the new importOSM procedure

CALL spatial.importOSM('/opt/spatial/minimal-indoor-model.osm');

results in

Failed to invoke procedure `spatial.importOSM`: Caused by: java.lang.NoClassDefFoundError: org/geotools/filter/text/cql2/CQLException

And just plainly

CALL spatial.procedures;

results in

Failed to invoke procedure `spatial.procedures`: Caused by: java.lang.NoSuchMethodError: org.neo4j.kernel.impl.proc.Procedures.getAll()Ljava/util/Set;

Can anybody reproduce this issue?

Note: this may be related to #290.

jexp commented 7 years ago

We just pushed a branch of spatial for 3.1 either you can build it locally or we'll provide a temporary jar to test here https://dl.dropboxusercontent.com/u/14493611/neo4j-spatial-0.24-neo4j-3.1.0-server-plugin.jar

m007 commented 7 years ago

I worked on these issues together with @schrieveslaach and we found out the following:

On the NoSuchMethodError

CALL spatial.procedures; resulting in java.lang.NoSuchMethodError: org.neo4j.kernel.impl.proc.Procedures.getAll()Ljava/util/Set; was due to a version mismatch. The method was renamed (see this line in 66a650497b). We initially fixed that ourself because we weren't aware of the above mentioned commit/3.1 branch. So this is no issue anymore, nice :+1:

On the NoClassDefFoundError

CALL spatial.importOSM('/opt/spatial/minimal-indoor-model.osm'); resulting in java.lang.NoClassDefFoundError: org/geotools/filter/text/cql2/CQLException is still not fixed. I tried building the server-plugin.jar myself in the 3.1 branch and one more time with the jar from your dropbox. However, we were able to fix that issue manually: We did find that, in fact, org/geotools/filter/text/cql2/CQLException.class is not included in the server-plugin.jar, so the manual solution was to just add that .class file. Afterwards we were good to go.

As the three of us know, NoClassDefFoundError just states that a class was available during compiling, but isn't anymore when used during runtime, so manually adding the .class file if it's in fact missing seemed straightforward.

What currently bothers me is, why is the class missing in the jar?

--

Note 1: I assume that org/geotools/filter/text/cql2/CQLException.class isn't the only missing class, since the server-plugin.jar doesn't even contain the folder structure of /text/cql2/ below org/geotools/filter/. Note 2: @schrieveslaach feel free to add or correct me.

schrieveslaach commented 7 years ago

@m007, that's correct. In fact, we added all .class files of org.geotool:gt-cql jar file to the server plugin jar.

wadael commented 7 years ago

on 20170812, using the latest sources (v3.1.4 I presume with a 3.1.3 server), built JARs (skipping tests, 2 are failing), I get a NoClassDefFoundError: org/geotools/filter/text/cql2/CQLException on a call spatial.importOSM('/home/jerome/Tools/neo/neo4j-community-3.1.3/import/map.osm')

call spatial.procedures() works

BTW, I get a FileNotFoundException if I use file:// protocol Would be even better if all plugins could interact with files coherently or allow both (with/without protocol), also using import folder as root.

wadael commented 7 years ago

I tried to add

org.geotools gt-cql ${geotools.version} compile

without luck. I'm going to bed with even more impostor syndrom

v14.4 is not latest but has the CQLException class

m007 commented 7 years ago

@wadael are you familiar with docker? If so, you could use this Dockerfile (which solved the issue for me):

FROM neo4j:3.1.1
RUN apk add --update zip unzip && rm -rf /var/cache/apk/*

RUN curl -s -L -o /var/lib/neo4j/plugins/neo4j-spatial-server-plugin.jar https://github.com/neo4j-contrib/m2/blob/master/releases/org/neo4j/neo4j-spatial/0.24-neo4j-3.1.1/neo4j-spatial-0.24-neo4j-3.1.1-server-plugin.jar?raw=true

# Patch the server-plugin.jar file with missing .class files
# The issue and patching were both documented here https://github.com/neo4j-contrib/spatial/issues/293
RUN curl -s -L -o /tmp/gt-cql.jar http://repo.boundlessgeo.com/main/org/geotools/gt-cql/14.4/gt-cql-14.4.jar && \
    unzip -q /tmp/gt-cql.jar -d /tmp && \
    cd /tmp && \
    zip -q -ur /var/lib/neo4j/plugins/neo4j-spatial-server-plugin.jar ./org/ && \
    rm -r /tmp/org /tmp/gt-cql.jar

EXPOSE 7474
CMD ["neo4j"]

This completely fixes the issues for server version 3.1.1 with plugin version 0.24.

wadael commented 7 years ago

@m007 Thank you, the dockerfile put me on tracks. I rage-copied all the dependencies of the project in $NEO_HOME/lib, with gt-cql amongst the jars. CALL spatial.importOSM('/home/jerome/Tools/neo/map.osm') worked. However, why adding the dep in the pom failed leaves me puzzled ... as it appears with mvn dependency:tree |grep cql
and scope is compile

m007 commented 7 years ago

@wadael glad to be able to help. As far as why the dependencies are missing question is concerned I have no idea either.

schrieveslaach commented 7 years ago

@m007 and @wadael, can you try the provided version, provided in #318? Remember to change the extension from .zip to .jar

schrieveslaach commented 7 years ago

Here is a Dockerfile

FROM neo4j:3.1.1
RUN apk add --update zip unzip && rm -rf /var/cache/apk/*

RUN curl -s -L -o /var/lib/neo4j/plugins/neo4j-spatial-server-plugin.jar https://github.com/neo4j-contrib/spatial/files/1227950/neo4j-spatial-0.24-neo4j-3.1.4-server-plugin.zip

EXPOSE 7474
CMD ["neo4j"]
m007 commented 7 years ago

After executing

CALL spatial.importOSM('/mnt/map.osm');

for a manually added map.osm file I can confirm that your proposed server-plugin.jar version works 👍 (i.e. does not throw the NoClassDefFoundError). I tested that using the above listed Dockerfile with one minor change:

FROM neo4j:3.1.4

matching the server version name in the .zip file.

craigtaverner commented 7 years ago

This issue due to the OSMLayer extending DynamicLayer which depended on CQL for specifying virtual layers. While OSMLayer itself does not need the CQL capability, this dependency caused the problem. I've added gt-cql to the server-plugin jar now, and released 0.24.1 with this change. See https://github.com/neo4j-contrib/spatial/releases/tag/0.24.1-neo4j-3.1.1