Maven:排除“META-INF / maven”来自JAR的文件夹 [英] Maven: Exclude "META-INF/maven" folder from JAR
问题描述
我使用 Maven
来构建 JAR
。当我检查 JAR
时,我在 META-INF中看到一个
文件夹。我希望它从构建中排除。我在 maven
文件夹 pom.xml
中的当前构建代码如下所示:
I use Maven
to build a JAR
. When I check the JAR
, I see a maven
folder inside the META-INF
folder. I want it to be excluded from the build. My current build code in the pom.xml
looks like this:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>Libraries</classpathPrefix>
<mainClass>com.company.Main</mainClass>
</manifest>
<manifestEntries>
<Built-By>Me</Built-By>
</manifestEntries>
</archive>
<!-- <excludes>
<exclude>META-INF/maven/**</exclude>
</excludes> -->
</configuration>
</plugin>
<!-- ...more plugins... -->
</plugins>
</build>
我读到使用 exclude
标签允许你要排除某些东西,但它不起作用。也许这只是指本地文件/文件夹? maven
文件夹不是源代码的一部分,它只是由 Maven
添加。
I read that using the exclude
tags allows you to exclude something but it doesn't work. Maybe this only refers to local files/folders? The maven
folder is not part of the source, it's just added by Maven
.
此答案有效,但使用了不同的工件,因此第二个当我将其粘贴到我的
。我想使用我当前的构建代码并排除 pom.xml
中时,会生成JAR maven
文件夹,如上所述。如何使用 maven
构建规则?
This answer kind of works but uses a different artifact hence a 2nd JAR
is generated when I paste it into my pom.xml
. I want to use my current build code and exclude the maven
folder like described above. How can it be done using maven
build rules?
推荐答案
maven-jar-plugin
使用 maven-archiver
来处理打包。它提供了配置 addMavenDescriptor
,默认情况下为 true
。将其设置为 false
应删除 META-INF / maven
目录。
The maven-jar-plugin
uses the maven-archiver
to handle packaging. It provides the configuration addMavenDescriptor
, which is true
by default. Setting it to false
should remove the META-INF/maven
directory.
...
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
....
</archive>
您可以找到参考这里。
这篇关于Maven:排除“META-INF / maven”来自JAR的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!