Setup Menus in Admin Panel

Maven Plugins

5 Maven Plugins

Maven is actually a plugin execution framework where every task is actually done by plugins.

Maven Plugins are generally used to :

  • create jar file
  • create war file
  • compile code files
  • unit testing of code
  • create project documentation
  • create project reports

A plugin generally provides a set of goals and which can be executed using following syntax:

mvn [plugin-name]:[goal-name]

For example, a Java project can be compiled with the maven-compiler-plugin’s compile-goal by running following command.

mvn compiler:compile

5.1 Plugin Types

Maven provided following two types of Plugins:

Build plugins
They execute during the build and should be configured in the <build/> element of pom.xml
Reporting plugins
They execute during the site generation and they should be configured in the <reporting/> element of the pom.xml

Following is the list of few common plugins:

Clean up target after the build. Deletes the target directory.
Compiles Java source files.
Run the JUnit unit tests. Creates test reports.
Builds a JAR file from the current project.
Builds a JAR file from the current project.
Generates Javadoc for the project.
Runs a set of ant tasks from any phase mentioned of the build.


5.2 How do I deploy a maven web application to Tomcat?

The Tomcat Maven Plugin (homepage at ), can be used to perform tasks such as deploying, redeploying, and undeploying a war file to Tomcat using the Tomcat Manager application.

After it has been set up, all you need to do is the following command to build and deploy a project to Tomcat using the maven tomcat plugin:

mvn tomcat:deploy

Now, let’s see how to set up a maven project to use the maven tomcat plugin.

First off, to access the Tomcat Web Application Manager, you must use a name/password with a manager role in Tomcat’s tomcat-users.xml file. In my Tomcat’s tomcat-users.xml file, the name “test” with password “test” fulfills this requirement.

<?xml version='1.0' encoding='utf-8'?>
<role rolename="manager"/>
<user username="test" password="test" roles="manager"/>

In my settings.xml file, I need to create a server entry specifying a name for my tomcat server and the manager name and password. I called my tomcat “mytomcat” and used “test” for username and “test” for password.

settings.xml server entry


Next, I added a tomcat-maven-plugin entry to the “mywebapp” project’s pom.xml. I specified the url to my Tomcat manager (by default this is http://localhost:8080/manager). I specified the server to be “mytomcat” so that the “mytomcat” server name and password in server.xml would be used to connect to Tomcat. I specified a path element to be “/mywebapp”, although this wasn’t really necessary since the build finalName is the same in this case.


complete pom.xml file is shown here:


<project xmlns="" 
<name>mywebapp Maven Webapp</name>
<artifactId>tomcat-maven plugin</artifactId> 
<artifactId>maven-eclipse plugin</artifactId>


Now, before using the tomcat maven plugin, I’ll log on to my manager application manually to see what happens. I log on with username “test” and password “test”. In this list of applications, the “mywebapp” application isn’t present yet.


Now, I’d like to create an Eclipse external tool configuration to perform a deploy of a selected project using the tomcat maven plugin. To do so, I first perform a “clean” phase to clean the selected project. After this I perform the “tomcat:deploy” goal to build and deploy the war file.

mvn clean tomcat~deploy
Working Directory:
clean tomcat:deploy

The external tool configuration is shown here.


I selected the “mywebapp” project in my Eclipse Navigator view and then ran the external tool that we just created. It generated the following console output:


In the Tomcat Manager, if I click the “List Applications” link, the “mywebapp” application appears at the bottom of the list.


5.3 How to Create a .war file from Eclipse using Maven Plugin

Motivation:Our requirement here is to generate single .war file using Maven which you could run on Apache Tomcat .

step1:Create Dynamic maven Web Project in to Eclipse ,

File->new->other->maven project->select create a simple project->enter groupid,artifactid->select packagin WAR->click finish.

If you dont find web.xml then you can do it by Pradeepit-DynamicWebProject –> RightClick –> Java EE Tools –> Generate Deployment Descriptor Stub.



You should see web.xml file immediately after that.Here is a project structure.


step2:Open your pom.xml file and update it with below code. We are packaging project as war using <packaging>war</packaging>.

<project xmlns="" 

Step3: Now Right Click on Project -> Run-As ->Maven Build


Step4:Maven clean install on project.


clean install:This command tells Maven to build all the modules, and to install it in the local repository. The local repository is created in your home directory (or alternative location that you created it), and is the location that all downloaded binaries and the projects you built are stored.

That’s it! If you look in the target subdirectory, you should find the build output and the final library or application that was being built.


Step5: Checkout your Build result in Eclipse console.

If u face the below error while running the maven build.

follow these steps

go to run configuration, create new maven build launch configuration where in the first tab you fill the base directory and the goal, then, go to jre tab and add to the vm args this config:-Dmaven.multiModuleProjectDirectory=%M2_HOME%where M2_HOME is an environment variable pointing to the base directory of your maven installation



That’s it. Now get your .war file from /target directory and deploy into Apache Tomcat or any other Web Container.









December 31, 2015

0 responses on "Maven Plugins"

Leave a Message

Your email address will not be published. Required fields are marked *

About Us

Pradeep Academy is an online & Training institute To make learning easy, interesting, affordable and accessible to millions of learners across the Globe. To create an alternative learning platform, using a unique learning methodology of live online interactive courses along with 24x7 support. We aim to empower our customers with skills which will help them get an edge in their careers and improve their lives.

Contact Us

Address :

PradeepIT Consulting Services Pvt Ltd

205,Brigade gardens, No.19 Church Street , Bangalore – 560001, Karnataka, India

Email :
Ph No: 08047363377
© Pradeep Academy.  Design & Developed by