Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven is not creating META-INF for spring boot project

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>

like image 393
chitwan Avatar asked Sep 13 '17 12:09

chitwan


People also ask

How do I create a meta-INF folder in spring boot?

Click 'Add Folder', click 'Create New Folder', type 'src/main/resources/META-INF', click 'Finish', click 'OK', Click 'Apply and Close', In the source folder '~/src/main/java', create a new Package 'hello' and a new Class file 'Application.

How do I add files to META-INF?

In src/main/resources , simply create a META-INF folder and place your files here. In this way, you could find them in the META-INF folder of the built JAR. Besides, you should remove the <resource> element you added in the pom.

How is meta-INF created?

The META-INF directory The manifest file that is used to define extension and package related data. This file is generated by the new "-i" option of the jar tool, which contains location information for packages defined in an application or extension.

What is Meta-INF and boot-INF?

This file contains meta data about the contents of the JAR. For example, there is an entry called Main-Class that specifies the name of the Java class with the static main() for executable JAR files. for more details. BOOT-INF : Spring Boot applications load from the BOOT-INF folder.


1 Answers

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>
like image 111
Naman Avatar answered Sep 18 '22 17:09

Naman