我依赖于Maven项目中的库,我发现库的JAR包含一些导致我的应用程序失败的包。我相信如果我可以以某种方式排除这些包,那么该库仍然可以工作,但我想通过Maven这样做,而不是自己黑客攻击JAR文件。有没有办法用Maven做到这一点?
答案 0 :(得分:3)
您可以查看maven-shade-plugin
。官方docs中显示了一个示例。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>junit:junit</artifact>
<includes>
<include>junit/framework/**</include>
<include>org/junit/**</include>
</includes>
<excludes>
<exclude>org/junit/experimental/**</exclude>
<exclude>org/junit/runners/**</exclude>
</excludes>
</filter>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>