Neo4j “No dependency satisfies type class org.neo4

2019-02-19 12:17发布

问题:

Neo4j Community 2.3.3 Linux (Ubuntu 14.04)

Trying to run a Java app which consumes a Kafka topic, process its messages while querying Neo4j, and writes them to another Kafka topic.

hduser@ubuntu:~$ java -jar gradle1-0.1.0.jar localhost:9092 musicgrp raw-events enriched-events bad-events /home/ubuntu/GeoLiteCity.dat
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.RuntimeException: Error starting org.neo4j.kernel.impl.factory.CommunityFacadeFactory, /home/hduser/neo4jdb2/data/graph.db
    at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.newFacade(GraphDatabaseFacadeFactory.java:143)
    at org.neo4j.kernel.impl.factory.CommunityFacadeFactory.newFacade(CommunityFacadeFactory.java:43)
    at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.newFacade(GraphDatabaseFacadeFactory.java:108)
    at org.neo4j.graphdb.factory.GraphDatabaseFactory.newDatabase(GraphDatabaseFactory.java:129)
    at org.neo4j.graphdb.factory.GraphDatabaseFactory$1.newDatabase(GraphDatabaseFactory.java:117)
    at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:185)
    at music.StreamApp.main(StreamApp.java:40)
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.NeoStoreDataSource@1d606256' was successfully initialized, but failed to start. Please see attached cause exception.
    at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:462)
    at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:111)
    at org.neo4j.kernel.impl.transaction.state.DataSourceManager.start(DataSourceManager.java:112)
    at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:452)
    at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:111)
    at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.newFacade(GraphDatabaseFacadeFactory.java:139)
    ... 6 more
Caused by: org.neo4j.kernel.impl.util.UnsatisfiedDependencyException: No dependency satisfies type class org.neo4j.kernel.api.index.SchemaIndexProvider
    at org.neo4j.kernel.impl.util.Dependencies.resolveDependency(Dependencies.java:78)
    at org.neo4j.kernel.impl.util.Dependencies.resolveDependency(Dependencies.java:74)
    at org.neo4j.kernel.NeoStoreDataSource.start(NeoStoreDataSource.java:507)
    at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:452)
    ... 11 more

This is my gradle.build, I read some post about keeping Neo4j jars out of the bundle ... by pointing to its jars with --classpath ... I'm new to Gradle, is this relevant ?

apply plugin: 'java'
apply plugin: 'application'
sourceCompatibility = '1.8' 
mainClassName = 'music.StreamApp'
repositories {
    mavenCentral()
}
version = '0.1.0'
dependencies { 
    compile 'org.apache.kafka:kafka-clients:0.9.0.0'
    compile 'com.maxmind.geoip:geoip-api:1.2.14'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.6.3'
    compile 'org.slf4j:slf4j-api:1.7.5'
    compile 'org.neo4j:neo4j:2.3.3'
}
jar { // c
manifest {
    attributes 'Main-Class': mainClassName
}
from {
    configurations.compile.collect {
        it.isDirectory() ? it : zipTree(it)
    }
} {
    exclude "META-INF/*.SF"
    exclude "META-INF/*.DSA"
    exclude "META-INF/*.RSA"
}
}

回答1:

My suspicion is that you don't have the META-INF/services/org.neo4j.kernel.extension.KernelExtensionFactory files in your jar correctly. Internally Neo4j uses JVM's ServiceLoader to load its components.

See https://github.com/neo4j/neo4j/blob/2.3/community/lucene-index/src/main/resources/META-INF/services/org.neo4j.kernel.extension.KernelExtensionFactory for the potentially missing piece.

I assume the right way to solve this is not by changing Gradle's default jar task, instead use a plugin that handles META-INF files correctly. I've made some good experiences with the shadow plugin.



回答2:

In my case (Neo4j Shell Tools 3.0.3, Gradle 2.13), adding mergeServiceFiles() was the key for resolving this issue:

plugins { id "com.github.johnrengelman.shadow" version "1.2.3" }

shadowJar {
    classifier = 'fat'
    mergeServiceFiles()
    manifest { attributes 'Main-Class': '...' }
}

There was no need to specify the exact file (META-INF/...).



标签: gradle neo4j