5
我正在使用maven shade插件爲我的項目生成合並jar。如預期的那樣產生的罐子,當我嘗試使用的jar和運行它,我得到一個Maven shade插件不會排除清單簽名文件
java.lang.SecurityException異常:無效的簽名文件的摘要清單 主要屬性錯誤。
我GOOGLE了上面的錯誤消息,許多人建議從META-INF目錄中排除清單簽名。因此,我已經包括了從目錄中排除這些文件的步驟[我看到名稱爲JARSIGN_.RSA
和JARSIGN_.SF
的兩個文件],但出於某種奇怪的原因,maven shade插件無法從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>
這個配置看起來是正確的,我用成功時也是這樣:http://pastebin.com/2ZQjehMi在'-X'上打開調試輸出來驗證插件是否被執行,並且稍後不會添加這些資源 –