簡體   English   中英

Maven Shade插件不排除清單簽名文件

[英]Maven shade plugin does not exclude the manifest signature files

我正在使用Maven Shade插件為我的項目生成一個整合罐。 該罐子按預期生成,當我嘗試使用該罐子並運行它時,我得到了一個

java.lang.SecurityException:清單主要屬性錯誤的無效簽名文件摘要。

我搜索了以上錯誤消息,很多人建議從META-INF目錄中排除清單簽名。 因此,我包括了從目錄中排除這些文件的步驟[我看到兩個文件名為JARSIGN_.RSAJARSIGN_.SF ],但是由於某些奇怪的原因,Maven JARSIGN_.SF插件無法從META-INF中排除這些文件目錄。 誰能解釋我可能做錯了什么? 我的pom.xml在下面,我用來生成jar的命令是:

mvn clean package shade:shade

pom.xml

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>

        <groupId>com.abc.xyz</groupId>
        <artifactId>myjar</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>jar</packaging>
        <url>http://maven.apache.org</url>

        <properties>
            <!-- A few custom properties -->
        </properties>


        <dependencies>
            <dependency>
                <groupId>com.google.code.gson</groupId>
                <artifactId>gson</artifactId>
                <version>2.3.1</version>
            </dependency>
            <dependency>
                <groupId>com.google.guava</groupId>
                <artifactId>guava</artifactId>
                <version>18.0</version>
            </dependency>
        <!-- Other The dependencies are here -->
        </dependencies>

        <repositories>
            <!-- Repository Information -->
        </repositories>
        <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>2.3.2</version>
                        <configuration>
                            <source>1.8</source>
                            <target>1.8</target>
                            <encoding>UTF-8</encoding>
                        </configuration>
                    </plugin>
                    <!-- Maven Shade Plugin -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-shade-plugin</artifactId>
                        <version>2.4.2</version>
                        <executions>
                            <!-- Run shade goal on package phase -->
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>shade</goal>
                                </goals>
                                <configuration>
                                    <filters>
                                        <filter>
                                            <artifact>*:*</artifact>
<!-- The below statement is not executed by shade plugin -->
                                            <excludes>
                                                <exclude>META-INF/*.SF</exclude>
                                                <exclude>META-INF/*.DSA</exclude>
                                                <exclude>META-INF/*.RSA</exclude>
                                            </excludes>
                                        </filter>
                                    </filters>                          
                                    <minimizeJar>true</minimizeJar>
                                    <artifactSet>
                                        <includes>
                                            <include>com.google.guava:guava</include>
                                            <include>com.google.code.gson:gson</include>
                                        </includes>
                                    </artifactSet>
                                    <transformers>
                                        <!-- add Main-Class to manifest file -->
                                        <transformer
                                            implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                            <manifestEntries>
                                                <Main-Class>com.abc.xyz.HelloWorld</Main-Class>
                                            </manifestEntries>
                                        </transformer>
                                    </transformers>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
        </build>
    </project>

也許插件的配置語法已更改,但是在過去使用shader插件1.5版對我有用:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>1.5</version>
    <configuration>
        <transformers>
            <transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
                <resource>META-INF/JARSIGN_.SF</resource>
            </transformer>
        </transformers>
    </configuration>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
        </execution>
    </executions>
</plugin>

我沒有嘗試使用通配符。 但是,查看文檔時 ,以下內容應排除所有.SF文件:

<resource>.SF</resource>

有關另一個示例,請參見此線程

使用shade插件3.2.1,以下對我有用。

<!-- language: lang-xml -->
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <filters>
                        <filter>
                            <artifact>*:*</artifact>
                            <excludes>
                                <exclude>META-INF/*.SF</exclude>
                                <exclude>META-INF/*.DSA</exclude>
                                <exclude>META-INF/*.RSA</exclude>
                            </excludes>
                        </filter>
                    </filters>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

在插件的文檔頁面( https://maven.apache.org/plugins/maven-shade-plugin/examples/includes-excludes.html )上,整個<configuration>塊顯示在<execution>標記內。 這是行不通的。 如上所示, <configuration>塊應位於<executions>標記之外。

我有一個類似的問題,無論我嘗試了什么設置,Shade插件顯然都沒有從META-INF目錄中排除文件。 我正在使用以下bash命令進行檢查:

mvn clean install
7za x target/built-jar-6.4.0.jar -aoa -o/tmp/unpacked/
ls /tmp/unpacked/META-INF/

問題實際上不在陰影插件本身中,而是在我解壓縮JAR的方式中-解壓縮命令會覆蓋文件,但它將舊文件保留在原位,使我認為設置有問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM