Tomcat-Maven 401错误:无法调用Tomcat管理器


问题内容

经历了StackOverFlow中显示的大多数错误,但仍然无法解决。我正在尝试部署SpringMVC应用程序。但是,我只是无法正常工作。

Maven部署错误:

[ERROR] Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:redeploy (default-cli) on project productmgmt: Cannot invoke Tomcat manager: Server returned HTTP response code: 401 for URL: http://localhost:8080/manager/text/deploy?path=%2Fproductmgmt&war=&update=true -> [Help 1]

Pom.xml:

<build>
        <finalName>productmgmt</finalName>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>tomcat-maven-plugin</artifactId>
                <configuration>
                    <url>http://localhost:8080/manager/text</url>
                    <path>/productmgmt</path>
                    <username>admin</username>
                    <password>password</password>
                </configuration>
            </plugin>
        </plugins>
    </build>

Tomcat的Users.xml

<role rolename="admin"/>
  <role rolename="manager"/>
  <user username="admin" password="admin" roles="admin,manager"/>
</tomcat-users>

更多信息:

[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

这对我有用

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

问题答案:

您的Maven配置将用户名和密码设置为admin/password。在Tomcat配置中,它们设置为admin/admin

切换pom.xml到拥有<password>admin</password>

另外,需要根据Tomcat docs更改管理员用户的角色。您将需要 manager-gui 角色访问HTML管理器,并且 manager-script
角色访问文本界面。