user2299050 user2299050 - 4 months ago 44
Java Question

Resolving conflicting dependencies (Maven)

I have a mavenproject in eclipse which relies on jars that include lucene.

This is my pom:

<dependency>
<groupId>org.dbpedia.spotlight</groupId>
<artifactId>core</artifactId>
<version>0.7</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-bolt</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-kernel</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-cypher</artifactId>
<version>3.0.3</version>
</dependency>


The issue is that I can not create/access my neo4j-Database if the dbpedia-spotlight-jar is included.

The Code

graphDb = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder( dir )
.setConfig( GraphDatabaseSettings.read_only, "true" )
.newGraphDatabase();


gives the errormessage

Exception in thread "main" java.lang.RuntimeException: Error starting org.neo4j.kernel.impl.factory.CommunityFacadeFactory, F:\DLs\DB
at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.newFacade(GraphDatabaseFacadeFactory.java:144)
at org.neo4j.kernel.impl.factory.CommunityFacadeFactory.newFacade(CommunityFacadeFactory.java:40)
at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.newFacade(GraphDatabaseFacadeFactory.java:108)
at org.neo4j.graphdb.factory.GraphDatabaseFactory.newDatabase(GraphDatabaseFactory.java:100)
at org.neo4j.graphdb.factory.GraphDatabaseFactory.lambda$createDatabaseCreator$203(GraphDatabaseFactory.java:89)
at org.neo4j.graphdb.factory.GraphDatabaseFactory$$Lambda$1/440434003.newDatabase(Unknown Source)
at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:183)
at neo4j.Neo4j.startServer(Neo4j.java:26)
at countAnnotator.Main.main(Main.java:35)
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.extension.KernelExtensions@78d4b13a' failed to initialize. Please see attached cause exception.
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.init(LifeSupport.java:416)
at org.neo4j.kernel.lifecycle.LifeSupport.init(LifeSupport.java:62)
at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:98)
at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.newFacade(GraphDatabaseFacadeFactory.java:140)
... 8 more
Caused by: java.lang.VerifyError: Cannot inherit from final class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.neo4j.kernel.api.impl.labelscan.storestrategy.BitmapDocumentFormat.<clinit>(BitmapDocumentFormat.java:40)
at org.neo4j.kernel.api.impl.labelscan.LuceneLabelScanIndexBuilder.<init>(LuceneLabelScanIndexBuilder.java:34)
at org.neo4j.kernel.api.impl.labelscan.LuceneLabelScanIndexBuilder.create(LuceneLabelScanIndexBuilder.java:49)
at org.neo4j.kernel.api.impl.labelscan.LuceneLabelScanStoreExtension.getLuceneIndex(LuceneLabelScanStoreExtension.java:90)
at org.neo4j.kernel.api.impl.labelscan.LuceneLabelScanStoreExtension.newInstance(LuceneLabelScanStoreExtension.java:79)
at org.neo4j.kernel.api.impl.labelscan.LuceneLabelScanStoreExtension.newInstance(LuceneLabelScanStoreExtension.java:40)
at org.neo4j.kernel.extension.KernelExtensions.init(KernelExtensions.java:69)
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.init(LifeSupport.java:406)
... 11 more


IF I have the dbpedia-spotlight as a dependency.

If I dont have it as a dependency, it runs just fine. I tried manually adding the jar as external archive and putting maven-dependencies to "Top" in the Buildpath-Order but to no avail.

Im fairly unexperienced in terms of maven so I wonder how one would go about resolving such an issue?
I need both jars to run my project (first step is wikification using dbpedia-spotlight, second step is calculating shortest path using neo4j - which both work as long as the other isnt included).

Putting the neo4j-part in a different proejct and the project in the buildpath of the original project didnt help either.

Thanks in advance!




So I did find a solution to my problem although I really dont understand why it is one - perhaps someone can explain it to me.

I still have the original project with both the dbpedia as well as the neo4j-jars.
I have also created a different empty project which only has the neo4j-dependencies and added this project to the first projects buildpath.

Now I can call both the wikification as well as neo4j from the first project and they work. My assumption is that this causes the 5.5 version to take priority over the 3.6 version and dbpedia is upwards-compatible while the neo4j 5.5-version was not downwards-compatible.

That might also be completely wrong since I know very little about how build paths work in terms of priority etc. and I stumbled upon this solution through luck.

Anyways - it works and thats whats important to me.



edit2: The proper solution was as simple as swapping the positions of dbpedia-spotlight and noe4j in the POM.

Answer

Regarding https://github.com/dbpedia-spotlight/dbpedia-spotlight/blob/master/pom.xml

org.dbpedia.spotlight in version 0.7 requires lucene version 3.6.0.

The only component of neo4j with dependencies to lucene, that I found googeling is neo4j-lucene-index. You did not list it in your pom, but may be you have it as a transitive (indirect) dependency. This works with lucene version 5.5, see neo4j-lucene-index/3.0.3

So what you have now does just not fit, you have to find versions of dbpedia that use the same version of lucene.

In both above links you find different versions of dbpedia and neo4j with their dependencies. Search the versions until you find some that use the same lucene version.

You can also run

mvn dependency:tree

on your project to get information about the used versions. Version conflicts should be shown there also.

Is it possible to use different versions ?

Short answer: No

Maven uses the dependency only to download the required jars and to put them in the classpath of your project. It will always put only one version of a jar file for every dependency into the classpath.

If this jar contains classes, that one of the other jars (dbpedia or neo4j) are not compatible with, you will get problems (exceptions).

That is not a maven specific problem, its just how java works.

At runtime neo4j and dbpedia want to use the same instances of lucene classes, and so they must somehow share the same version of lucene.

However, if you find a lucene version thats close to what dbpedia and neo4j use, you can give it a try, sometimes it works...

Comments