Java – Maven: exclude the “meta-inf / Maven” folder from the jar

I use Maven to build jars When I checked the jar, I saw a maven folder in the meta - inf folder I want it to be excluded from the build I'm in POM The current build code in XML is as follows:

<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>

I read that using exclusion tags allows you to exclude something, but it doesn't work Maybe this just refers to local files / folders? The Maven folder is not part of the source code, it is just added by Maven

This answer works a little, but uses different artifacts, so when I paste it into my POM A second jar is generated when the XML is I want to use my current build code and exclude the Maven folder, as described above How to build rules using Maven?

Solution

Maven jar plugin uses Maven archiver to handle packaging It provides configuration addmavendescriptor, which is true by default Setting it to false should delete the meta - inf / Maven directory

...
<archive>
   <addMavenDescriptor>false</addMavenDescriptor>
   ....
</archive>

You can find the reference here

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>