Tomcat-maven-plugin 401错误

时间:2011-09-07 17:48:23

标签: maven-2 maven maven-plugin maven-3

我正在学习tomcat基础知识,当我尝试在tomcat上部署我的web应用程序时,我收到以下错误

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

根据这一点,似乎war文件位置没有被传递给tomcat manager.i在我的tomcat-user.xml

中有以下条目
tomcat-users>
<user name="admin" password="admin" roles="admin,manager" /><!--
  NOTE:  The sample user and role entries below are wrapped in a comment
  and thus are ignored when reading this file. Do not forget to remove
  <!.. ..> that surrounds them.
-->

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


</tomcat-users>

以下是pom.xml

的详细信息
<build>
        <plugins>
        <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <packagingExcludes>WEB-INF/web.xml</packagingExcludes>
                </configuration>
            </plugin>
            <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>tomcat-maven-plugin</artifactId>
        <configuration>
                <warFile>${project.build.directory}/${project.build.finalName}.war</warFile>
                <url>http://localhost:8080/manager/html</url>
                <server>myserver</server>
                <path>/mkyWebApp</path>

        </configuration>
</plugin>

        </plugins>
    </build>

在我的setting.xml中有条目

<server>
      <id>Tomcat6.x</id>

      <username>admin</username>
      <password>admin</password>
    </server>

我不确定这里到底出了什么问题。在这方面的任何帮助都会有所帮助。

4 个答案:

答案 0 :(得分:5)

更改

<server>
  <id>Tomcat6.x</id>
  <username>admin</username>
  <password>admin</password>
</server>

<server>
  <id>myserver</id>
  <username>admin</username>
  <password>admin</password>
</server>

如果您使用的是tomcat 7,请使用

 <url>http://localhost:8080/manager/html</url>

如果是tomcat 6

<url>http://localhost:8080/manager</url>

启动tomcat运行tomcat7:deploy或tomcat6:deploy

答案 1 :(得分:4)

您需要将settings.xml中的凭据映射到pom.xml上的服务器配置。

在您的情况下,已完成此操作但设置服务器的<id>元素,以匹配pom.xml中服务器的主机名。

由于您指的是localhost,因此ID必须也是localhost。 更改主机名时,还必须更新settings.xml。

答案 2 :(得分:1)

当我也遇到这个问题时。我的问题是使用较旧的

 <groupId>org.codehaus.mojo</groupId>

而不是使用

<groupId>org.apache.tomcat.maven</groupId>

我的设置如下

〜/ .m2 / settings.xml

    <settings>
        <servers>
            <server>
              <id>localhost</id>
              <username>tomcat</username>
              <password>tomcat</password>
            </server>
        </servers>
    </settings>

<强>的pom.xml

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat6-maven-plugin</artifactId>
    <configuration>
            <url>http://localhost:8080/manager</url>
            <server>localhost</server>
    <path>/myapppath</path>         
    </configuration>
</plugin> 

tomcat / conf / tomcat-users.xml

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

答案 3 :(得分:0)

我建议你使用这个插件:

 <groupId>org.codehaus.cargo</groupId>
  <artifactId>cargo-maven2-plugin</artifactId>
  <version>1.1.2</version>

对Tomcat7非常有帮助。我对mojo <groupId>org.codehaus.mojo</groupId>也有同样的问题 但现在,使用货物插件,部署运行顺利如丝。