• 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

  • 相关阅读:
    37.1 net-- udp传输
    37 net 网络编程
    review
    java day02 记录
    36.2 线程生命周期
    36.1 线程锁
    36 Thread 多线程
    35 编码 ASCII Unicode UTF-8 ,字符串的编码、io流的编码
    34.6 Properties(k,v存储) 和io流结合使用
    今日学习总结
  • 原文地址:https://www.cnblogs.com/bigbigtree/p/6735250.html
Copyright © 2020-2023  润新知