Sotirios-Efstathios Maneas

About Sotirios-Efstathios Maneas

Sotirios-Efstathios (Stathis) Maneas is a postgraduate student at the Department of Informatics and Telecommunications of The National and Kapodistrian University of Athens. His main interests include distributed systems, web crawling, model checking, operating systems, programming languages and web applications.

How to deploy Maven based war file to Tomcat example

In this tutorial, we will show you how to use the Apache Tomcat Maven plugin, in order to package and deploy a war file to Apache Tomcat. You can download the plugin from the official page.

In this example, we use the following tools on a Windows 7 platform:

  • Apache Maven 3.1.1
  • Apache Tomcat Maven Plugin
  • JDK 1.7
  • Apache Tomcat 7

Please refer to this guide here, in order to verify that you know how to create a Web application project, using Apache Maven.

1. Create a user in Apache Tomcat

First of all, we must create a user with administrator rights for the Apache Tomcat. Using the terminal (Linux or Mac) or the command prompt (Windows), navigate to the folder where the Apache Tomcat is installed. Then, navigate to the folder called conf and add the following code snippet to the tomcat-users.xml file, inside the <tomcat-users> tag:

<role rolename="manager"/>
<role rolename="admin"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="admin" password="admin" roles="admin,manager,manager-gui,manager-script"/>

We have now successfully created a new user, called admin.

2. Create a user in Apache Maven

Using the terminal (Linux or Mac) or the command prompt (Windows), navigate to the folder where the Apache Maven is installed. Recall that the MAVEN_HOME environment variable points to the home folder of Maven. Then, navigate to the folder called conf and add the following code snippet to the settings.xml file, inside the servers tag:


We created a user with the name TomcatServer, along with its credentials.

3. Add Apache Tomcat Maven plugin as a Dependency

The next step is to declare the Apache Tomcat Maven plugin as a dependency to our project. Inside the pom.xml, we must add the following code snippet:


By using the above code snippet, we specify that our project must be deployed on http://localhost:8080/manager/text, in the path /javaCodeGeeks, using the credentials of the TomcatServer user.

A sample pom.xml file is shown below:


<project xmlns="" xmlns:xsi=""

   <name>SampleWebApplication Maven Webapp</name>





4. Deploy the project to Apache Tomcat

The first thing to do, before deploying our project, is start the Apache Tomcat. From the Windows command line, we execute the following command:


Now, using the terminal (Linux or Mac) or the command prompt (Windows), we navigate to the folder where our project is located. Then, we issue the command:

mvn tomcat:deploy

This command packages our project in a war file and deploys it to the Apache Tomcat. In order to verify that our installation is successful, we must go to the manager page of the Apache Tomcat and check that /javaCodeGeeks actually exists:



Finally, if we want to deploy our project and the javaCodeGeeks.war file already exists, we must issue the following command:

mvn tomcat:redeploy

Notice that the Apache Tomcat must already be running, before we issue this command.
This was a tutorial on how to use the Apache Tomcat Maven plugin to deploy a war file to Apache Tomcat.

Related Whitepaper:

Java Essential Training

Author David Gassner explores Java SE (Standard Edition), the language used to build mobile apps for Android devices, enterprise server applications, and more!

The course demonstrates how to install both Java and the Eclipse IDE and dives into the particulars of programming. The course also explains the fundamentals of Java, from creating simple variables, assigning values, and declaring methods to working with strings, arrays, and subclasses; reading and writing to text files; and implementing object oriented programming concepts. Exercise files are included with the course.

Get it Now!  

Examples Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy
All trademarks and registered trademarks appearing on Examples Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Examples Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below: