Java.lang.NoClassDefFoundError: org / apache / lucene / codecs / Codec

I have a project that requires Lucene ( 4.3.0 ) and add the following dependencies: Lucene-core, Lucene-parsers-general, Lucene-queries, Lucene-queryparser.

And, after adding the lucene-codecs dependency, also get the same error.

but the lucene-core core contains a codec class

----- start of exception -----

 I/TestRunner(2443): java.lang.NoClassDefFoundError: org/apache/lucene/codecs/Codec I/TestRunner(2443): at org.apache.lucene.index.LiveIndexWriterConfig.<init>(LiveIndexWriterConfig.java:118) I/TestRunner(2443): at org.apache.lucene.index.IndexWriterConfig.<init>(IndexWriterConfig.java:144) I/TestRunner(2443): at com.my.search.SearchIndexManager.newWriter(SearchIndexManager.java:301) I/TestRunner(2443): at com.my.search.SearchIndexManager.addIndexState(SearchIndexManager.java:95) I/TestRunner(2443): at com.my.SearchOperation.addIndexer(SearchOperation.java:68) I/TestRunner(2443): at com.my.test.SearchOperationTest.testSearchWithFilter(SearchOperationTest.java:208) I/TestRunner(2443): at java.lang.reflect.Method.invokeNative(Native Method) I/TestRunner(2443): at java.lang.reflect.Method.invoke(Method.java:511) I/TestRunner(2443): at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214) I/TestRunner(2443): at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199) I/TestRunner(2443): at junit.framework.TestCase.runBare(TestCase.java:134) I/TestRunner(2443): at junit.framework.TestResult$1.protect(TestResult.java:115) I/TestRunner(2443): at junit.framework.TestResult.runProtected(TestResult.java:133) I/TestRunner(2443): at junit.framework.TestResult.run(TestResult.java:118) I/TestRunner(2443): at junit.framework.TestCase.run(TestCase.java:124) I/TestRunner(2443): at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190) I/TestRunner(2443): at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175) I/TestRunner(2443): at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555) I/TestRunner(2443): at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1584) I/TestRunner(2736): Caused by: java.lang.IllegalArgumentException: A SPI class of type org.apache.lucene.codecs.Codec with name 'Lucene42' does not exist. You need to add the corresponding JAR file supporting this SPI to your classpath.The current classpath supports the following names: [] I/TestRunner(2736): at org.apache.lucene.util.NamedSPILoader.lookup(NamedSPILoader.java:109) I/TestRunner(2736): at org.apache.lucene.codecs.Codec.forName(Codec.java:95) I/TestRunner(2736): at org.apache.lucene.codecs.Codec.<clinit>(Codec.java:122) I/TestRunner(2736): ... 19 more 

----- end exception -----

+4
source share
2 answers

Googling has interesting results.

https://issues.apache.org/jira/browse/LUCENE-4204

As stated above, the Android APK developer deletes some files in the META-INF / services directory that Lucene requires. They offer some workarounds, such as adding the necessary files from lucene tanks directly to the APK using some ant tasks performed after the completion of the APK creation. Just be careful, as some lucene banks use the same files in the META-INF / services directory, and you can overwrite them shortly.

I would suggest that you use the android maven plugin as they already applied the fix for this (see https://code.google.com/p/maven-android-plugin/issues/detail?id=97 ). Just use the latest version of the plugin (or any version above 3.2.1).

+5
source

It seems that your problem is not that the Codec class was not found, and the other class (SPI provider) was not found (see Caused by ). If you see the description of the Lucene package at the bottom (also see here ), this class is declared by the SPI provider in the META-INF folder of one of your cans.

So, look for your banks to find the META-INF/services/org.apache.lucene.codecs.Codec file, open it and look at the class name. You are missing a jar that contains this class

Hope this helps

+3
source

Source: https://habr.com/ru/post/1492551/


All Articles