Java Maven shade插件不排除清单签名文件
我正在使用maven shade插件为我的项目生成一个整合jar。jar是按预期生成的,当我尝试使用jar并运行它时,我得到一个 java.lang.SecurityException:的签名文件摘要无效 清单主属性错误 我用谷歌搜索了上面的错误消息,许多人建议从META-INF目录中排除清单签名。因此,我加入了从目录中排除这些文件的步骤[我看到两个文件的名称分别为Java Maven shade插件不排除清单签名文件,java,maven,jar,maven-shade-plugin,Java,Maven,Jar,Maven Shade Plugin,我正在使用maven shade插件为我的项目生成一个整合jar。jar是按预期生成的,当我尝试使用jar并运行它时,我得到一个 java.lang.SecurityException:的签名文件摘要无效 清单主属性错误 我用谷歌搜索了上面的错误消息,许多人建议从META-INF目录中排除清单签名。因此,我加入了从目录中排除这些文件的步骤[我看到两个文件的名称分别为JARSIGN_uu2;.RSA和JARSIGN_u2;.SF],但出于某种奇怪的原因,maven shade插件无法从META-I
JARSIGN_uu2;.RSA
和JARSIGN_u2;.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>
4.0.0
com.abc.xyz
myjar
1.0-快照
罐子
http://maven.apache.org
com.google.code.gson
格森
2.3.1
番石榴
番石榴
18
org.apache.maven.plugins
maven编译器插件
2.3.2
1.8
1.8
UTF-8
org.apache.maven.plugins
maven阴影插件
2.4.2
包裹
阴凉处
*:*
META-INF/*.SF
META-INF/*.DSA
META-INF/*.RSA
真的
番石榴:番石榴
com.google.code.gson:gson
com.abc.xyz.HelloWorld
可能插件的配置语法已更改,但这在过去的着色器插件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>
另一个例子见此。对于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>
org.apache.maven.plugins
)整个
块显示在
标记内。这是行不通的。
块应该在上面所示的
标记之外。我遇到了一个类似的问题,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/
问题其实不在shade插件本身,而是在我解包JAR的过程中——解包命令覆盖了文件,但它保留了旧文件,让我觉得我的设置有问题。这个配置似乎正确,我成功地使用了相同的方法:打开debug output-X
来验证插件是否已执行,以及这些资源是否在以后添加
mvn clean install
7za x target/built-jar-6.4.0.jar -aoa -o/tmp/unpacked/
ls /tmp/unpacked/META-INF/