Tomcat Maven Plugin重新部署返回404错误的原因是什么?
Let's break down why you're hitting this 404 error with the tomcat7:redeploy goal and how to fix it.
Core Issue
The tomcat7:redeploy goal depends entirely on Tomcat's Manager application to handle deployment operations. When you run mvn tomcat7:run, you're starting an embedded Tomcat instance—and by default, this embedded setup does NOT include the Manager application. That’s why you can’t access http://localhost:8080/manager, and why the redeploy call fails with a 404 when trying to reach /manager/text/deploy.
Solution 1: Use a Standalone Tomcat Installation (Recommended for Deployment Workflows)
If you want to use redeploy reliably, it’s better to work with a standalone Tomcat instance instead of the embedded one:
Install and start standalone Tomcat 7
Download Tomcat 7, extract it, and launch it usingbin/startup.sh(Linux/macOS) orbin/startup.bat(Windows).Configure user permissions for Manager access
Editconf/tomcat-users.xmlin your standalone Tomcat directory to add a user with themanager-scriptrole (required for the Maven plugin to interact with Manager):<tomcat-users> <!-- Keep existing users if any, add this entry --> <user username="tomcat" password="tomcat" roles="manager-script,manager-gui"/> </tomcat-users>Restart Tomcat to apply this change.
Update your pom.xml plugin configuration
Point the plugin to your standalone Tomcat’s Manager text interface:<plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <!-- URL of standalone Tomcat's Manager text endpoint --> <url>http://localhost:8080/manager/text</url> <!-- Reference to a server entry in your Maven settings --> <server>TomcatStandalone</server> <!-- Context path for your application --> <path>/app</path> </configuration> </plugin>Add server credentials to Maven settings.xml
Open your Mavensettings.xml(usually located at~/.m2/settings.xmlorconf/settings.xmlin your Maven installation) and add a server entry matching the<server>value above:<servers> <server> <id>TomcatStandalone</id> <username>tomcat</username> <password>tomcat</password> </server> </servers>Run the redeploy command
Stop any running embedded Tomcat instances, start your standalone Tomcat, then execute:mvn package tomcat7:redeployThis should work now, as the plugin is communicating with the fully functional Manager app in your standalone Tomcat.
Solution 2: Enable Manager in the Embedded Tomcat (For Testing Only)
If you need to use the embedded Tomcat with redeploy (not recommended for production), you can force it to include the Manager app:
Update pom.xml to include the Manager dependency
Modify your plugin configuration to add the Tomcat Manager WAR as an additional dependency:<plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <server>TomcatEmbedded</server> <path>/app</path> <additionalDependencies> <additionalDependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-manager</artifactId> <version>7.0.55</version> <!-- Matches the Tomcat version used by plugin 2.2 --> <type>war</type> </additionalDependency> </additionalDependencies> <!-- Configure embedded Tomcat users --> <tomcatUsers> <user username="admin" password="admin" roles="manager-script"/> </tomcatUsers> </configuration> </plugin>Add server credentials to Maven settings.xml
Add a server entry forTomcatEmbeddedusing the username/password you set in the plugin configuration.Test the setup
Start the embedded Tomcat withmvn tomcat7:run, then in a separate terminal runmvn package tomcat7:redeploy. You should now be able to accesshttp://localhost:8080/manager/html(note the/htmlsuffix) and the redeploy should succeed.
Quick Verification Step
Before running redeploy, always confirm the Manager app is accessible:
- For standalone Tomcat: Visit
http://localhost:8080/managerand log in with your configured user. - For embedded Tomcat: Visit
http://localhost:8080/manager/htmland log in.
If the Manager loads without issues, your redeploy command should work without 404 errors.
内容的提问来源于stack exchange,提问作者marcioggs

