EDUCBA

EDUCBA

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

Maven WAR 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 WAR Plugin

Maven WAR Plugin

Definition of Maven WAR Plugin

Maven war plugin is responsible for collecting dependencies of classes and artifacts of web applications and needs to package the same into the archive of a web application. It is the default goal that was invoked during the packaging phase of products during the type of war. War plugin is used to speed up the testing during a development phase.

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)

Introduction to Maven WAR Plugin

The war in place is the variation of exploding, whereas our web application is generated into the web application of the source directory into the web app by default. There are four types of war plugin goals available as follows:

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

  1. Exploded – This goal is used to create an exploded web application into a specified directory.
  2. Help – This type of goal displays the help information from the war plugin. We are using the mvn command to show the details of the parameters.
  3. InPlace – This goal type is used to generate the web application into the source directory of the web application.
  4. War – This goal type is used to build the war file.

To use the war plugin in the java application, we have required the Jdk version as 1.7 and above. We have needed the maven version as 3.1.0. For memory and disk usage, we do not have a minimum requirement; as per the application, we can increase or decrease the memory.

How to Use Maven WAR Plugin?

The below example shows how we can use the package phase as follows. To define the package war plugin, we need to add the below code into the pom.xml file where we need to define the packaging as war.
Code:

<groupId> com.example </groupId>
<artifactId> maven_war </artifactId>
<version> 0.0.1-SNAPSHOT </version>
<packaging> war </packaging>
<name> maven_war </name>
<description> Project for maven_war </description>
<properties>
<java.version> 1.8 </java.version>
</properties>

Use Maven WAR Plugin 1

In the below example, we are using the invocation of war.exploded goal to use the war plugin are as follows. While using the exploded goal we are using the plugin directory to define the war plugin into the pom.xml file.

Code:

<plugin>
<groupId> org.apache.maven.plugins </groupId>
<artifactId> maven-war </artifactId>
<version> 3.3.2 </version>
<configuration>
<webappDirectory> /dir </webappDirectory>
</configuration>
</plugin>

Use Maven WAR Plugin 2

Use Maven WAR Plugin 3

The below example shows to use of the war plugin by using war.inplace goal are as follows. To define the inplace war plugin we are using the mvn command, also we can run our project by using a maven build.

mvn compile war:inpace

Use Maven WAR Plugin 4

Use Maven WAR Plugin 5

Maven WAR Web Application

The below example shows the application as follows. While developing the application into the maven war plugin first we need to create the template. The below steps show how we can create an application of the war plugin as follows.

  • In this step, we are creating the war plugin project template into the spring initializer. We are giving the name of the maven project as maven_war. We are defining the packaging as war and selecting the java version as 8.

Group name – com.example              Artifact – maven_war

Name – maven_war               Packaging – war

Java version – 8

Web Application 1

  • After creating maven war project, in this step, we are opening the war plugin application project into the spring tool suite.

Web Application 2

  • After creating the project template of the war plugin and opening the project in this step we are checking the project structure and files.

Web Application 3

  • Basically in the java application, there are four ways to use the war plugin. The first way to use the war plugin as use the package phase by using the project package type as war invocation as follows. In the below example, we are defining the package name as war as follows.

Code:

<groupId> com.example </groupId>
<artifactId> maven_war_plugin </artifactId>
<version> 0.0.1-SNAPSHOT </version>
<packaging> war </packaging>
<name> maven_war_plugin </name>
<description> Project for maven_war_plugin </description>
<properties>
<java.version> 1.8 </java.version>
</properties>

Web Application 4

  • In the below step, we are running the project by using maven build. We using mvn command for the same.

Web Application 5

Maven WAR File Content

The war plugin of maven is responsible for compiling and collecting the dependencies, resources, classes from web applications. We have defined multiple goals in the war plugin i.e. inplace, war, and exploded. In the below example we are adding the maven war plugin into the pom.xml file. After adding the maven war plugin then we are running the maven install command.

Code:

<plugin>
<groupId> org.apache.maven.plugins </groupId>
<artifactId> maven-war </artifactId>
<version> 3.3.2 </version>
</plugin>

File Content 1

File Content 2

By using the exploded command we are generating the war file into the directory which was inside the target directory. In the below example, we are including or excluding the content of war file as follows. By using the war plugin we are filtering the contents of a war file as follows.

Code:

<plugin>
<artifactId> maven-war </artifactId>
<version> 3.3.1 </version>
<configuration>
<webResources>
<resource>
<directory> War resources </directory>
</resource>
</webResources>
</configuration>
</plugin>

File Content 3

File Content 4

Maven WAR Setting

At the time of using the war plugin into the maven application, we are using the below required parameter as follows.

  • Output directory
  • War source directory
  • Web app directory
  • Work directory

Also, there are multiple optional parameters available that we are using in the application of the war plugin. The maven war plugin is allowing us to customize the file of the manifest. We are adding the classpath into the manifest file. It is useful at the time when war files are in a more complex structure and also it is more useful when we need to share the dependencies into multiple modules. In the below example, we are using maven war settings as follows.

Code:

<plugin>
<artifactId> maven-war-plugin </artifactId>
<version> 3.3.1 </version>
<configuration>
<archive>
<manifest>
<addClasspath> true </addClasspath>
</manifest>
</archive>
</configuration>
</plugin>

Maven WAR Setting 1

Maven WAR Setting 2

Key Takeaways

  • The war plugin is nothing but web application archives of web application resources. The war file is used to deploy the web application onto the application server.
  • Inside the war file, web components are packed into one unit, it includes the jar files.

FAQ

Given below are the FAQs mentioned:

Q1. Why are we using the maven war plugin in the application of maven?

Answer: War plugin is used to deploy the application of java into the application server. Maven war plugin is the tool for build management.

Q2. How many types of goals we are using in the maven war plugin?

Answer: We are using four types of goals in the war plugin i.e. war.exploded, war.help, war.war, and war.inplace.

Q3. Which version we have required at the time of using the war plugin in web application?

Answer: We need to use the maven version of 3.1.0 and above and for java we need to use the JDK 1.7 version.

Conclusion

To use the maven war plugin in the java application we have required the Jdk version as 1.7 and above. Maven war plugin is responsible for collecting dependencies of classes and artifacts of web applications and needs to package the same into the archive of the web application.

Recommended Articles

This is a guide to Maven WAR Plugin. Here we discuss the introduction and how to use the Maven WAR Plugin along with the web application, file content, and settings. You may also have a look at the following articles to learn more –

  1. Maven Local Repository
  2. IntelliJ Maven
  3. Spring Boot War
  4. tomcat deploy war
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