Search code examples
javaspringmavenpom.xmlmaven-jetty-plugin

What exactly do the maven-jar-plugin Maven plugin? What is the difference using or not using this plugin?


I am working on a simple Spring console application (it is a batch having a class with the classic main() method()) and I have the following doubt about the pom.xml Maven file. This file only contains the required Spring dependencies needed to work. When I run the Maven install statment it generates the related .jar compiled application into the target directory of my project.

I was looking to another similar old project on which I worked in the past and into its pom.xml I can find this maven-jar-plugin plugin:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
        <archive>
            <manifest>
                <mainClass>com.myCompany.main.MainClass</mainClass>
            </manifest>
        </archive>
    </configuration>
</plugin>

So what this maven-jar-plugin exactly does (also without using it the maven install statment generates a compiled .jar file). What is the difference using or not using this plugin?


Solution

  • The jar plugin allow us to define a default manifest file. With that option, the file located at ${project.build.outputDirectory}/META-INF/MANIFEST.MF will be the manifest file in the jar The maven jar plugin provides the capability to build jars files, if you define that your project is packaged as a jar file, maven will call implicitly to this plugin. We don´t need to define it inside pom.xml it will be downloaded and executed when maven needs it.So does not matter whether you use this inside your pom or not,it will get automatically loaded by maven if needed.

    Refer this link for better undertanding https://examples.javacodegeeks.com/enterprise-java/maven/maven-jar-plugin-example/