【问题标题】:Tomcat-maven-plugin 401 errorTomcat-maven-plugin 401 错误
【发布时间】:2011-11-12 09:17:53
【问题描述】:

我正在学习 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 管理器。我的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>

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

【问题讨论】:

  • 尝试在 settings.xml 的 'id' 字段中放入 'localhost' 而不是 'Tomcat6.x'。
  • @Tarlog:使用localhost是什么概念?因为使用这个值解决了这个问题所以我想知道
  • 我会添加一个明确的答案:)

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


【解决方案1】:

改变

<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

【讨论】:

    【解决方案2】:

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

    在您的情况下,这已完成,但设置服务器的 &lt;id&gt; 元素,以匹配 pom.xml 中的服务器主机名。

    因为你指向localhost,所以id也必须是localhost。 更改主机名时,还必须更新 settings.xml。

    【讨论】:

    • 感谢 Tarlog 的描述 :)
    【解决方案3】:

    它在plugin configuration docs 中:Maven 设置中的server/id 标签必须与您的 POM 文件中的 configuration/server 值匹配,即在 POM 文件中放入 &lt;server&gt;Tomcat6.x&lt;/server&gt;

    您在 POM 文件中的 tomcat-maven-plugin 条目还有一些其他小问题:

    1. 您缺少&lt;version&gt;1.1&lt;/version&gt; 标签,
    2. Tomcat 管理器 URL 中的 /html 后缀是不必要的(参见 &lt;url&gt; 标记的默认值)。

    【讨论】:

      【解决方案4】:

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

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

      【讨论】:

        【解决方案5】:

        我建议你使用这个插件:

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

        对Tomcat7很有帮助。我对 mojo &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt; 有同样的问题 但现在,使用 Cargo 插件,部署运行顺畅。

        【讨论】:

          猜你喜欢
          • 2014-11-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-06-04
          • 2012-02-16
          • 1970-01-01
          • 2012-07-12
          相关资源
          最近更新 更多