maven is not creating META-INF for spring boot pro

2019-07-22 15:53发布

问题:

When I build my Spring boot project, it creates an target folder and target/classes also, but it doesn't create any META-INF. I have also included dependency -

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
    <archive>
        <index>true</index>
        <manifest>
            <addClasspath>true</addClasspath>
        </manifest>
        <manifestEntries>
            <mode>development</mode>
            <url>${project.url}</url>
            <key>value</key>
        </manifestEntries>
    </archive>
</configuration>

回答1:

Two ways to do it.

  1. Form the maven-jar-plugin documentation :

Please note that the following parameter has been completely removed from the plugin configuration:

useDefaultManifestFile

If you need to define your own MANIFEST.MF file you can simply achieve that via Maven Archiver configuration like in the following example:

<configuration>
    <archive>
        <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
    </archive>
</configuration>

where in you can place your MANIFEST.MF under src/main/resources/META-INF folder of your project. The command

mvn clean package

would build the project jar with the src/main/resources by default.

  1. The notes at usage of the plugin states that

Starting with version 2.1, the maven-jar-plugin uses Maven Archiver 3.1.1. This means that it no longer creates the Specification and Implementation details in the manifest by default. If you want them you have to say so explicitly in your plugin configuration.

Which can be done using:

<manifest>
     <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
     <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>