如何从阴影jar中排除* .DSA和* .SF文件?

时间:2013-07-15 16:12:22

标签: java maven maven-shade-plugin

我在pom.xml中有一节

 <filters>
   <filter>
      <artifact>*:*</artifact>
         <excludes>
            <exclude>META-INF/*.SF</exclude>
            <exclude>META-INF/*.DSA</exclude>
         </excludes>
   </filter>
</filters>

我想从最终jar中排除* .SF和* .DSA文件。 但我收到以下消息:

[INFO] No artifact matching filter *:*

并不排除文件。 有谁知道如何克服它?

3 个答案:

答案 0 :(得分:13)

实际上,您无需指定组ID即可进行全局过滤,只需使用正确的通配符语法即可。例如,如果要从jar中排除所有* .RSA文件,请将artifactId指定为*:*:*:*

<filters>
    <filter>
        <artifact>*:*:*:*</artifact>
        <excludes>
            <exclude>*.RSA</exclude>
        </excludes>
    </filter>
</filters>

答案 1 :(得分:5)

我遇到了同样的问题。通过使我的工件选择器更具体来修复它,例如

<artifact>bouncycastle:*</artifact>

整个块看起来像这样:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <transformers>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <mainClass>com.mycompany.MainClass</mainClass>
                    </transformer>
                </transformers>
                <filters>
                    <filter>
                        <artifact>bouncycastle:*</artifact>
                        <excludes>
                            <exclude>META-INF/*.SF</exclude>
                            <exclude>META-INF/*.DSA</exclude>
                            <exclude>META-INF/*.RSA</exclude>
                        </excludes>
                    </filter>
                </filters>
                <shadedArtifactAttached>true</shadedArtifactAttached>
                <shadedClassifierName>standalone</shadedClassifierName>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>

答案 2 :(得分:0)

这是一个古老的问题,但是没有一个答案对我有用。结合起来做到了:

<filters>
    <filter>
        <artifact>*:*:*:*</artifact>
        <excludes>
            <exclude>META-INF/*.RSA</exclude>
            <exclude>META-INF/*.SF</exclude>
            <exclude>META-INF/*.DSA</exclude>
        </excludes>
    </filter>
</filters>