You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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.


If you want to use redeploy reliably, it’s better to work with a standalone Tomcat instance instead of the embedded one:

  1. Install and start standalone Tomcat 7
    Download Tomcat 7, extract it, and launch it using bin/startup.sh (Linux/macOS) or bin/startup.bat (Windows).

  2. Configure user permissions for Manager access
    Edit conf/tomcat-users.xml in your standalone Tomcat directory to add a user with the manager-script role (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.

  3. 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>
    
  4. Add server credentials to Maven settings.xml
    Open your Maven settings.xml (usually located at ~/.m2/settings.xml or conf/settings.xml in 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>
    
  5. Run the redeploy command
    Stop any running embedded Tomcat instances, start your standalone Tomcat, then execute:

    mvn package tomcat7:redeploy
    

    This 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:

  1. 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>
    
  2. Add server credentials to Maven settings.xml
    Add a server entry for TomcatEmbedded using the username/password you set in the plugin configuration.

  3. Test the setup
    Start the embedded Tomcat with mvn tomcat7:run, then in a separate terminal run mvn package tomcat7:redeploy. You should now be able to access http://localhost:8080/manager/html (note the /html suffix) 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/manager and log in with your configured user.
  • For embedded Tomcat: Visit http://localhost:8080/manager/html and log in.

If the Manager loads without issues, your redeploy command should work without 404 errors.

内容的提问来源于stack exchange,提问作者marcioggs

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 14:37:33