How to deploy Maven based war file to Tomcat
Here we show you how to use Maven-Tomcat plugin to package and deploy a WAR file to Tomcat.
1. Tomcat Authentication
First, add an user with administrator access right for Tomcat. To add Tomcat user, edit this file – “%TOMCAT_PATH%/conf/tomcat-users.xml“.
File : tomcat-users.xml
<?xml version='1.0' encoding='utf-8'?> <tomcat-users> <role rolename="manager"/> <role rolename="admin"/> <user username="admin" password="password" roles="admin,manager"/> </tomcat-users>
Later, you will use the user “admin” to do the deployment.
2. Maven Authentication
In Maven side, you need to add the same user authentication information in “%MAVEN_PATH%/conf/settings.xml“.
File : settings.xml
//... <server> <id>TomcatServer</id> <username>admin</username> <password>password</password> </server> //...
3. Maven-Tomcat-Plugin
Declare “Maven-Tomcat plugin” and related Tomcat server detail in your pom.xml file.
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>tomcat-maven-plugin</artifactId> <configuration> <url>http://127.0.0.1:8080/manager</url> <server>TomcatServer</server> <path>/mkyongWebApp</path> </configuration> </plugin>
See a full pom.xml file.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.mkyong</groupId> <artifactId>mkyongweb-core</artifactId> <packaging>war</packaging> <version>1.0</version> <name>mkyongweb-core Maven Webapp</name> <url>http://maven.apache.org</url> <build> <plugins> <!-- Maven Tomcat Plugin --> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>tomcat-maven-plugin</artifactId> <configuration> <url>http://127.0.0.1:8080/manager</url> <server>TomcatServer</server> <path>/mkyongWebApp</path> </configuration> </plugin> <!-- Maven compiler plugin --> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> </plugins> </build> </project>
During deployment, it tell Maven to deploy the WAR file to Tomcat server (http://127.0.0.1:8080/), on path “/mkyongWebApp“, and using “TomcatServer” (in
settings.xml) username and password for authentication.4. Deploy to Tomcat
Issue “mvn tomcat:deploy” to package your project in a WAR file, and deploy it to Tomcat server. To verify it, just access to the Tomcat’s manager page and make sure “/mkyongWebApp” path is existed.
URL : http://127.0.0.1:8080/manager/

For subsequent deployment, where “mkyongWebApp” web application is existed, you should use “
mvn tomcat:redeploy” instead.For more usages, please refer to this Maven-Tomcat plugin page.

I also had following problem:
Cannot invoke Tomcat manager: Server returned HTTP response code: 403 for URL
while using Tomcat 7. The solution was using maven goal “tomcat7:deploy”. For details see http://tomcat.apache.org/maven-plugin-2.0/tomcat7-maven-plugin/plugin-info.html
[ERROR] Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:redeploy (default-cli) on project cms-sql: Cannot invoke Tomcat manager: Server returned HTTP response code: 403 for URL: http://10.70.4.200:9090/manager/deploy?path=%2FCMSService&war=&update=true -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:redeploy (default-cli) on project cms-sql: Cannot invoke Tomcat manager
I had trouble deploying as I had incorrectly set the roles in my tomcat users file.
I fixed it using:
POM.xml
org.codehaus.mojo
tomcat-maven-plugin
http://127.0.0.1:8080/manager/html
TomcatServer
/[yourApp]
admin
password
tomcat_users.xml
I had trouble deploying as I had incorrectly set the roles in my tomcat users file.
I fixed it using:
Tomcat-users xml
Work for me only with
Thanks both.
hi
below warning is coming while deploying the war file with mvn tomcat:deploy
[WARNING] Unrecognised tag: ‘server’ (position: START_TAG seen … | variables for plugins in the POM.\n |\n |–>\n\n… @183:9) @ /usr/local/apache-maven/conf/settings.xml, line 183, column 9
I was also getting same error
[ERROR] Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:exploded (default-cli) on project Struts-Redirect: Cannot invoke Tomcat manager: http://127.0.0.1
:9091/manager/deploy?path=%2FStruts-Redirect&war=file%3A%2FE%3A%2Fstufff%2F111111111struts%2FStruts2-Hello-World-Example%2FStruts2Example%2Ftarget%2FStruts-Redirect%2F ->
[Help 1]
Paste below lines in manager.xml present at $CATALINA_BASE/conf/[enginename]/[hostname] folder ($CATALINA_BASE\conf\Catalina\localhost\manager.xml)
For more information refer to Manager App HOW-TO @
http://tomcat.apache.org/tomcat-6.0-doc/manager-howto.html
If it doesn’t work put your settings.xml file under the location m2/settings.xml file.
Hope this helps.
how can i make war file from maven project?
mvn war:warormvn packageto run the full building life cyclesThank you so much mkyong.
Hi Mr. Mkyong,
Thank you very much for this handy explanation.
I have a question related to the usage of proxy server.
To access to my remote server I have to pass by a proxy server.
How can I deal with this issue?
Thank you very much
Best Regards
Thanks MKYong and Santosh! This helped so much!
hii mr mkyong
how to integration struts2 , spring3 and hibernate 3 using maven
thank you mr mkyong
hii mr mkyong how to integration struts2,hibernate3,spring3 using maven
thamk you mr mkyong
When i am trying to deploy the project using “mvn tomcat:deploy” I am getting the error below. I have made the changes as specified by you. Can you please help me out.
Do you see war file in your project build folder?
Yes.
The war file is there.
The error show above is after maven starts deploying the war.
I searched on google also but didn’t find any solution for this.
How about if you copy the Maven generated war file into Tomcat folder manually?
Hi,
I am using tomcat 7.0.6.The following changes worked for me.
1)File : tomcat-users.xml
2)maven: settings.xml
3)pom.xml
Hi mkyong,
I am getting following error while running the code.
my pom.xml is
and
settings.xml contains server information
How this tomcat plugin works? How tomcat plugin contact to tomcat server.DO i need to start tomcat server manually for that?
Thanks in advance,
King George