问题描述
我正在使用maven shade插件为我的项目生成一个合并jar。 jar是按预期生成的,当我尝试使用jar并运行它时,我得到一个
I am using the maven shade plugin to generate a consolidate jar for my project. The jar is generated as expected and when i try to use the jar and run it, i get a
我用Google搜索了上述错误消息,很多人建议排除来自META-INF目录的清单签名。因此,我已经包括从目录中排除这些文件的步骤[我看到两个文件的名称 JARSIGN_.RSA
和 JARSIGN_.SF
],但由于某些奇怪的原因,maven shade插件无法从META-INF目录中排除这些文件。谁能解释一下我可能做错了什么?我的pom.xml在下面,我用来生成jar的命令是:
I googled the above error message and many people have suggested to exclude the manifest signatures from the META-INF directory. Thus i have included the step to exclude these files from the directory [i see two files by the name JARSIGN_.RSA
and JARSIGN_.SF
], but for some strange reason, maven shade plugin is unable to exclude these files from the META-INF directory. Could anyone explain me what i might be doing wrong? My pom.xml is below and the command that i am using to generate the jar is:
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>
推荐答案
可能插件的配置语法已经改变,但是这对我来说在过去使用着色器插件版本1.5:
Maybe the configuration syntax for the plugin has changed, but this worked for me in the past with version 1.5 of the shader plugin:
<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
文件:
I have not tried to use wildcards. But looking at the documentation the following should exclude all .SF
files:
<resource>.SF</resource>
请参阅。
这篇关于Maven shade插件不排除清单签名文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!