从生成的jar文件中排除META-INF/maven文件夹 [英] Exclude META-INF/maven folder from the generated jar file
问题描述
我正在尝试创建一个jar文件,其中提取了jar中所有必需的类.但是对于像 log4j 这样的一些依赖jar,它会在META-INF/maven/*
内创建一些文件夹.我有一个限制,即将放置生成的jar文件的服务器将无法连接Internet.因此,如果此META-INF/maven/*
文件夹中有任何内容,那么它将给我一个错误.
I am trying to create a jar file which has all the necessary classes extracted within the jar. But for few dependent jar like log4j, it creates some folders inside META-INF/maven/*
. I have a limitation that the server in which I will be placing the generated jar file will not have Internet connectivity. So if there is any content in this META-INF/maven/*
folder then it gives me an error.
我的maven描述符如下所示
My maven descriptor looks like the following
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<minimizeJar>true</minimizeJar>
<finalName>myclient</finalName>
</configuration>
</plugin>
</plugins>
</build>
我能够在生成的jar中提取所需的类文件,但是在META-INF
下仍会生成maven文件夹.我必须手动删除文件夹才能使所有工作正常.请提供有关如何自动从生成的jar文件中删除Maven文件夹的建议.
I am able to extract the required class files in the generated jar but the maven folder is still getting generated under META-INF
. I have to manually delete the folder to make everything work. Please advice on how to automate this removal of maven folder from the generated jar file.
推荐答案
You can use filters inside the maven-shade-plugin
configuration to exclude everything that is under META-INF/maven
for every artifact:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/maven/**</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
maven-jar-plugin
的解决方案可以在此处找到.
A solution for the maven-jar-plugin
can be found here.
这篇关于从生成的jar文件中排除META-INF/maven文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!