[英]Exclude META-INF/maven folder from the generated jar file
I am trying to create a jar file which has all the necessary classes extracted within the jar. 我试图创建一个jar文件,其中提取了jar中所有必需的类。 But for few dependent jar like log4j , it creates some folders inside
META-INF/maven/*
. 但是对于像log4j这样的少数依赖jar,它会在
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. 我有一个限制,即将放置生成的jar文件的服务器将无法连接Internet。 So if there is any content in this
META-INF/maven/*
folder then it gives me an error. 因此,如果此
META-INF/maven/*
文件夹中有任何内容,那么它将给我一个错误。
My maven descriptor looks like the following 我的Maven描述符如下所示
<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>
I am able to extract the required class files in the generated jar but the maven folder is still getting generated under META-INF
. 我可以在生成的jar中提取所需的类文件,但仍在
META-INF
下生成maven文件夹。 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.
请提供有关如何自动从生成的jar文件中删除maven文件夹的建议。
You can use filters inside the maven-shade-plugin
configuration to exclude everything that is under META-INF/maven
for every artifact: 您可以在
maven-shade-plugin
配置中使用过滤器 ,以针对每个工件排除META-INF/maven
的所有内容:
<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>
A solution for the maven-jar-plugin
can be found here . 可以在这里找到
maven-jar-plugin
解决方案。
Simple add this to either it is a jar,war,ear plugin 简单地将其添加到一个jar,war,ear插件中
<configuration>
....
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
....
</configuration>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.