An SPI class of type org.apache.lucene.codecs.PostingsFormat with name 'Lucene50' does not exist. You need to add the corresponding JAR file supporting this SPI to your classpath. The current classp


背景介绍:

当ES中guava库与hive等组件的库冲突时,对Elasticsearch库进行shade,relocate解决库冲突问题。

当使用"org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"对资源进行重定向后,仍旧报错,报错信息:

An SPI class of type org.apache.lucene.codecs.PostingsFormat with name 'Lucene50' does not exist.  You need to add the corresponding JAR file supporting this SPI to your classpath.  The current classp

根本原因:需要对META-INF/services资源合并。

Java spi机制:
     “当服务的提供者,提供了服务接口的一种实现之后,在jar包的META-INF/services/目录里同时创建一个以服务接口命名的文件。该文件里就是实现该服务接口的具体实现类。而当外部程序装配这个模块的时候,就能通过该jar包META-INF/services/里的配置文件找到具体的实现类名,并装载实例化,完成模块的注入。 基于这样一个约定就能很好的找到服务接口的实现类,而不需要再代码里制定。
     jdk提供服务实现查找的一个工具类:java.util.ServiceLoader” 《【java规范】Java spi机制浅谈》
 

 

解决方法有两种:

1、Maven配置

 <transformers>
    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer" />
    <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>

2、手动在工程的src目录下创建目录META-INF/services/ 并手动将上面两个红框里的内容做合并,这样所有路径都包含了,缺一不可。

参考:

http://stackoverflow.com/questions/35066597/elasticsearch-in-a-runnable-jar-lucene-problems

http://rocketeer.leanote.com/post/dcab93e5bf35


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM