Reputation: 16901
I'm trying to setup a project using Maven wherein two incompatible projects are used (Elasticsearch and Neo4j). These two projects both make use of Lucene but different and incompatible versions. As it turned out this is impossible! Fortunately, I need Elasticsearch at runtime and Neo4j at test time. So theoretically, I should be fine. But I'm not!
As for the shared Lucence package, Neo4j makes use of an older version and because of that I explicitly named the older versions in <dependencyManager>
with <scope>test</scope>
. Lots of runtime errors have been resolved this way. But now, I'm facing a NoClassDefFoundError
exception running tests, within Elasticsearch's file saying:
java.lang.NoClassDefFoundError: org/apache/logging/log4j/Logger
at org.elasticsearch.common.logging.Loggers.getLogger(Loggers.java:101)
at org.elasticsearch.search.suggest.completion2x.Completion090PostingsFormat.<clinit>(Completion090PostingsFormat.java:78)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at org.apache.lucene.util.NamedSPILoader.reload(NamedSPILoader.java:72)
at org.apache.lucene.util.NamedSPILoader.<init>(NamedSPILoader.java:51)
at org.apache.lucene.util.NamedSPILoader.<init>(NamedSPILoader.java:38)
at org.apache.lucene.codecs.PostingsFormat$Holder.<clinit>(PostingsFormat.java:49)
at org.apache.lucene.codecs.PostingsFormat.forName(PostingsFormat.java:112)
at org.apache.lucene.codecs.lucene54.Lucene54Codec.<init>(Lucene54Codec.java:161)
at org.apache.lucene.codecs.lucene54.Lucene54Codec.<init>(Lucene54Codec.java:81)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at org.apache.lucene.util.NamedSPILoader.reload(NamedSPILoader.java:72)
at org.apache.lucene.util.NamedSPILoader.<init>(NamedSPILoader.java:51)
at org.apache.lucene.util.NamedSPILoader.<init>(NamedSPILoader.java:38)
at org.apache.lucene.codecs.Codec$Holder.<clinit>(Codec.java:47)
at org.apache.lucene.codecs.Codec.getDefault(Codec.java:140)
at org.apache.lucene.index.LiveIndexWriterConfig.<init>(LiveIndexWriterConfig.java:120)
at org.apache.lucene.index.IndexWriterConfig.<init>(IndexWriterConfig.java:140)
at org.neo4j.kernel.api.impl.index.IndexWriterConfigs.standard(IndexWriterConfigs.java:69)
at org.neo4j.kernel.api.impl.index.partition.WritableIndexPartitionFactory.createPartition(WritableIndexPartitionFactory.java:45)
at org.neo4j.kernel.api.impl.index.AbstractLuceneIndex.open(AbstractLuceneIndex.java:98)
...
This does not make sense to me at all, because:
int i = 0;
in my test).org/apache/logging/log4j/Logger
class is available, I instantiated a static logger in my test class and the class is found this time: final static org.apache.log4j.Logger logger = Logger.getLogger(ApplicationTests.class);
The funny thing is that this static logger object is instantiated successfully before the exception is thrown in Elasticsearch's code!Any idea why I'm facing this exception?
To demonstrate the issue, I've created this project on GitHub which you can clone. Try and run the test dummyTest
and you'll see the exception.
Upvotes: 4
Views: 14874
Reputation: 61
Hi have found the answer here: https://discuss.elastic.co/t/issue-with-elastic-search-5-0-0-noclassdeffounderror-org-apache-logging-log4j-logger/64262/3
It seems that log4j 2.7 does not work with ElasticSearch 5.0.0. And you also need to add a dependency on the libraries slf4j-simple
and log4j-to-slf4j
along with log4j-api
.
For me, it worked with:
log4j-api
version 2.8.2slf4j-simple
version 1.7.25log4j-to-slf4j
version 2.8.2elasticsearch
version 5.4.0Upvotes: 6