EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

Maven Jar Plugin

Secondary Sidebar
Maven Tutorial
  • Maven Basic and advance
    • What is Maven
    • How to Install Maven
    • Maven Commands
    • Maven GroupId
    • Maven WAR Plugin
    • Maven Build Command
    • Maven Failsafe Plugin
    • Maven Profile
    • IntelliJ Maven
    • Maven Enforcer Plugin
    • Maven Javadoc Plugin
    • Maven WAR Plugin
    • Maven Build Command
    • Maven GroupId
    • Maven Force Update
    • Maven Encrypt Password
    • Maven Environment Variables
    • AssertJ Maven
    • Maven Run Single Test
    • Maven kafka-clients
    • Maven Quickstart Archetype
    • Maven Install Dependencies
    • Maven XMLBeans
    • Maven Local Repository
    • Maven Versions
    • Maven Jar Plugin
    • Maven Assembly Plugin
    • Maven exec plugin
    • Maven Central Repository
    • Maven Surefire
    • Maven Deploy
    • Maven Phases
    • Maven Archetype
    • Maven Skip Test
    • Maven Dependency Scope
    • Maven Shade Plugin
    • Maven Repository Spring
    • Maven Eclipse Plugin
    • Maven Exclude Dependency
    • Maven Life Cycle
    • Maven Repository
    • Maven POM File
    • Maven Plugins
    • What is Maven Plugins
    • Maven Interview Questions
    • Maven Flags
    • Maven Project
    • Maven Settings.XML
Home Software Development Software Development Tutorials Maven Tutorial Maven Jar Plugin

Maven Jar Plugin

Introduction to Maven Jar Plugin

Maven jar plugin is used to build the jar files, if we defined our project as a jar file maven jar project will call it implicitly. We have no need to define it inside the pom.xml file this will be downloaded when it was required by maven. We can also define it into the pom.xml file to control the specified features of the jar file which was generated from maven jar file. The jar plugin has two goals defines i.e. jar and test-jar, default goal of jar plugin is jar.

How Maven Jar Plugin works?

Basically, maven jar plugin has two goals defined first one is jar and the second one is test-jar. Jar will allow the package into the main class as a jar file. Test jar will allow the test class package as our jar file. If suppose we have defined the default goal as jar then we have no need to define the goal into the pom.xml file. Maven jar will automatically take or invoke the goals when it has needs for this file.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,064 ratings)

Below are the apache maven assembly plugin version available for the general use.

  • Version 2.0.x
  • Version 2.1.x
  • Version 2.2.x
  • Version 2.3.x
  • Version 2.4.x
  • Version 2.5.x
  • Version 2.6.x
  • Version 3.0.x
  • Version 3.1.x
  • Version 3.2.x

It will allow us to use the default manifest file. We are storing this manifest file into the project directory path. The apache version 2.1 jar plugin will use the maven Archiver 2.1, so from this version, we have no need to add the implementation and specification details into the manifest file. If suppose we need to add this details into the file then we are defining the same manually. We can also alter the default content from the manifest file by using the element of archive configuration. Basically, the maven jar will provide build jar capability. We are creating a maven jar file with the use of the following content.

Below is the basic file syntax to create pom.xml.

<project> -- Start of the project.
<modelVersion> /* start of model version section */ 4.0.0</modelVersion> -- start of model version section
<groupId> /* start of groupid section */ name of groupid </groupId> -- End of groupid section
<artifactId> /* start of artifactId section */ core</artifactId> -- End of artifactId section
<version> /* start of version section */ name of version</version> -- End of version section
<!-- <packaging>jar</packaging> -->
</project> -- End of the project

Using it, jar is the default package which was required to set. We are creating the jar file using the mvn package command. The phase of the package is responsible to bundle the files into an artefact. Using the maven jar file we have no need for any additional dependencies to create an executable jar.

Below is the important parameter which was needed to use at the time of creating it.

  • model version
  • groupId
  • artifactId
  • version
  • packaging

Model version is nothing but the version number which we are using at the time of creating pom.xml file using it. GroupId is nothing but the group name which was we have using at the time of creating pom.xml file using it. ArtifactId is nothing but the artefact name which was we have using at the time of creating pom.xml file using it. The version parameter is nothing but the snapshot version which was we have using at the time of creating pom.xml file using it. We can create jar files using the default manifest file, custom manifest file, exclude, include files and by using the additional jars.

Examples of Maven Jar Plugin

Given below are the examples mentioned:

Example #1

Using default manifest file to create project using maven jar plugin.

  • The below example shows use of the default manifest file to create a project using it.

Code:

<project> -- Start of project section.
<parent> -- Start of parent section.
<groupId> /* Start of groupid section. */org.springframework.boot</groupId> -- -- end of groupid section.
<artifactId> /* Start of artifactid section. */ spring-boot-starter-parent</artifactId> -- -- end of artifactid section.
<version> /* Start of version section. */2.5.4</version>
<relativePath/> /* Start of relativepath section. */ <!-- lookup parent from repository -->
</parent> -- end of parent section.
<version> /* Start of version section. */ 0.0.1-SNAPSHOT</version>
<name> /* Start of name section. */ maven</name>
<description> /* Start of description section. */ Maven jar</description> -- -- end of description section.
<properties>
<java.version> /* Start of java version section. */ 1.8</java.version>
</properties>
<dependencies> -- Start of dependencies section.
<dependency> -- start of dependency section.
<groupId> /* Start of groupid section. */ org.springframework.boot</groupId> -- -- end of groupid section.
<artifactId> /* Start of artifactId section. */ spring-boot-starter-web</artifactId>
</dependency> -- end of dependency section.
</project> -- end of project section.
# maven package

Output:

Maven Jar Plugin 1

Using default manifest file

Example #2

Using a custom manifest file to create project using the maven jar plugin.

  • The below example shows the use of a custom manifest file to create a project using it.

Code:

<build> -- Start of build section.
<plugin> -- Start of second plugin section.
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration> -- Start of configuration section.
<archive> -- Start of archive section.
<index>true</index>
<manifest> -- Start of manifest section.
</manifest>
<manifestEntries> -- Start of manifestEntries section.
<javacodegeeks> /* Start of javacodegeeks section */ maven jar plugin example</javacodegeeks>
<codification> /* Start of codification section */ ${project.build.sourceEncoding}</codification> -- End of codification section.
<key>maven jar plugin </key>
</manifestEntries> -- End of manifestEntries section.
</archive> -- End of archive section.
</configuration> -- End of configuration section.
</plugin> -- End of plugin section.
</build> -- End of build section.
# maven package

Output:

Using custom manifest file to create project

Maven Jar Plugin 4

Conclusion

It is used to build the jar file. If suppose we have defined our project as jar file, the maven project will implicitly invoke this plugin. Model version, groupId, artifactId, version and packaging are important parameters while creating it.

Recommended Articles

This is a guide to Maven Jar Plugin. Here we discuss the introduction, how maven jar plugin works? and examples respectively. You may also have a look at the following articles to learn more –

  1. Maven Central Repository
  2. Maven Deploy
  3. Maven Surefire
  4. Jetty Maven plugin
Popular Course in this category
Maven Training (4 Courses, 6 Projects)
  4 Online Courses |  6 Hands-on Project |  26+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

Special Offer - Maven Training (4 Courses, 6 Projects) Learn More