Deploying a Maven Web Application to Tomcat 9 Using the Tomcat Manager
Tomcat 9 does not provide a dedicated Maven plugin. The Tomcat Manager interface, however, is backward-compatible, so the Tomcat 7 Maven Plugin can be used to deploy to Tomcat 9. This guide shows two setups:
- Using the Tomcat 8 Maven Plugin (historical build that requires custom plugin repositories)
- Using the Tomcat 7 Maven Plugin to deploy to a locally running Tomcat 9
Option A: Referencing the Tomcat 8 Maven Plugin from custom repositories
Some legacy builds used tomcat8-maven-plugin 3.0-r1655215. If you need it, add plugin repositories and the plugin declaration:
<!-- pom.xml -->
<pluginRepositories>
<pluginRepository>
<id>alfresco-public</id>
<url>https://artifacts.alfresco.com/nexus/content/groups/public</url>
</pluginRepository>
<pluginRepository>
<id>alfresco-public-snapshots</id>
<url>https://artifacts.alfresco.com/nexus/content/groups/public-snapshots</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>beardedgeeks-releases</id>
<url>http://beardedgeeks.googlecode.com/svn/repository/releases</url>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat8-maven-plugin</artifactId>
<version>3.0-r1655215</version>
</plugin>
</plugins>
</build>
Using Tomcat 7 Maven Pluginn to deploy to Tomcat 9
1) Create a deployment user in Tomcat 9
Edit the Tomcat users file at TOMCAT_HOME/conf/tomcat-users.xml and add a user with the Manager roles. Choose your own strong password; the example uses deployer/s3cr3t!.
<!-- TOMCAT_HOME/conf/tomcat-users.xml -->
<tomcat-users>
<!-- Manager roles required for CLI/HTTP text API -->
<role rolename="manager-script"/>
<role rolename="manager-gui"/>
<role rolename="manager-status"/>
<role rolename="manager-jmx"/>
<user username="deployer"
password="s3cr3t!"
roles="manager-script,manager-gui,manager-status,manager-jmx"/>
</tomcat-users>
2) Store credentials in Mavan settings
Add a server entry in your Maven settings (usually ~/.m2/settings.xml). The id is referenced from the project POM.
<!-- ~/.m2/settings.xml -->
<settings>
<servers>
<server>
<id>tomcat9-local</id>
<username>deployer</username>
<password>s3cr3t!</password>
</server>
</servers>
</settings>
3) Configure the Tomcat Maven Plugin in you're POM
Use the Tomcat 7 Maven Plugin to talk to Tomcat 9’s Manager app. Ensure the server id matches the one in settings.xml. Specify the Manager text URL and the webapp context path.
<!-- pom.xml -->
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<!-- Must match <server><id> in ~/.m2/settings.xml -->
<server>tomcat9-local</server>
<!-- Tomcat Manager text interface -->
<url>http://localhost:8080/manager/text</url>
<!-- Deployed context path (e.g., http://localhost:8080/myapp) -->
<path>/myapp</path>
<!-- Allow overwriting deployments on redeploy -->
<update>true</update>
</configuration>
</plugin>
</plugins>
</build>
Running the deployment
- Start you're local Tomcat 9 instance
- Build the application
mvn clean package
- Deploy to Tomcat 9 via the Manager API
mvn tomcat7:deploy
- Verify the application at
http://localhost:8080/myapp
- To redeploy after changes
mvn tomcat7:redeploy
Troubleshooting
- Confirm Tomcat is running and the Manager app is reachable:
- http://localhost:8080
- http://loclahost:8080/manager/html (GUI)
- http://localhost:8080/manager/text (API)
- Ensure tomcat-users.xml contains manager-script (required for text API)
- Verify the Maven settings.xml server id and credentials match the POM configuration