名为“Lucene54”的类型为org.apache.lucene.codecs.Codec的SPI类不存在

时间:2016-07-13 20:55:29

标签: java lucene spi

使用lucene-core-5.5.2我在weblogic服务器上遇到问题a。独立搜索应用程序可以工作,但当我部署为WEB APP时,它失败并出现以下错误

Exception type is 'java.lang.ExceptionInInitializerError'. Runtime error: java.lang.IllegalArgumentException: An SPI class of type org.apache.lucene.codecs.Codec with name 'Lucene54' does not exist. You need to add the corresponding JAR file supporting this SPI to your classpath. The current classpath supports the following names: []

我尝试在classes/下创建文件夹结构,因为META-INF/services/添加了来自lucene-core-5.5.2.jar META-INF\services\目录的所有文件,也创建了META-INF\services\的jar文件,并添加到了类路径中,但它无法识别META-INF/services加载SPI

任何帮助都会非常感激。

5 个答案:

答案 0 :(得分:3)

请在

中添加以下文件

文件夹:META-INF/services/

档案:org.apache.lucene.codecs.Codec

文字:org.apache.lucene.codecs.lucene54.Lucene54Codec

请在https://anwaarlabs.wordpress.com/2017/02/25/lucene-an-spi-class-of-type-org-apache-lucene-codecs-codec-with-name-does-not-exist/

上查看详细说明的解决方案

答案 1 :(得分:0)

它是固定的我在weblogic app server classpath中添加了lucene jar并且它按预期工作。我不知道为什么它没有检测到我的应用程序li​​b文件夹,因为它也在类路径上,但看起来像某种程度上SPI需要jar和META-INF在app服务器类路径

答案 2 :(得分:0)

我用gradle使用建议的解决方案来建造一个"胖罐" (包含所有相关jar的可执行jar)here

但它没有用到:我得到了与Lucene有关的这个模糊的错误,但是在测试或构建或正常运行时却没有,只有在构建一个胖罐时。

我的解决方案是使用shadow jar:来自gradle.build的代码:

buildscript {
    repositories { jcenter() }
    dependencies { // fatjar
        classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.4' }
}
apply plugin: 'com.github.johnrengelman.shadow'
shadowJar {
    baseName = project.name
    classifier = null
    version = project.version
}

答案 3 :(得分:0)

我将以下代码添加到配置标记

        <transformers>
    <transformer  implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                  <resource>META-INF/services/org.apache.lucene.codecs.Codec</resource>
                  <resource>META-INF/services/org.apache.lucene.codecs.PostingsFormat</resource>
     /transformer>
         </transformers>

此外,我还在依赖项标记

的顶部添加了lucene-core依赖项
                    <dependency>
                        <groupId>org.apache.lucene</groupId>
                        <artifactId>lucene-core</artifactId>
                        <version>5.5.0</version>
                     </dependency>

答案 4 :(得分:0)

请确保您包含在项目中的Lucene jar与错误提到的Lucene编解码器具有相同的版本。例如。如果错误指出LuceneCodec62,则您的项目中应该包含lucene-6.x.x jar。