我尝试使用 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?
最佳答案
是的,这是可能的,只需要添加一个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>
关于Maven Shade - 更改文件名并替换文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31586697/