Maven Shade - 更改文件名并替换文本

时间:2015-07-23 11:58:02

标签: maven elasticsearch lucene maven-shade-plugin

我尝试使用Maven Shade并包装ElasticSearch jar。

原因,为什么我这样做是因为我的项目中的Lucene版本之间存在冲突。

但是当我使用Shade时,我发现了问题。它不会更改META-INF/services中的文件名,也不会更改该特定文件中的FQN。

我需要更改org.apache.lucene.codecs.Codec文件及其内容。因为如果这个文件保留其名称,那么我会收到错误 "Caused by: java.lang.IllegalArgumentException: An SPI class of type shaded_lucene_4_10_4.org.apache.lucene.codecs.Codec with name 'Lucene410' does not exist. You need to add the corresponding JAR file supporting this SPI to your classpath. The current classpath supports the following names: []"

是否可以使用Maven Shade插件包装ElasticSearch?

Here is my pom.xml

1 个答案:

答案 0 :(得分:3)

是的,只需添加一个ServicesResourceTransformer条目即可。 像这样:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.4.1</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <transformers>
            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
              <mainClass>org.myorg.esclient.App</mainClass>
            </transformer>
            <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
          </transformers>
        </configuration>
      </execution>
    </executions>
  </plugin>

检查: http://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html#ServicesResourceTransformer