2011-09-07 63 views
4

我正在學習tomcat的基礎,雖然我試圖在Tomcat上部署我的web應用程序我收到以下錯誤Tomcat的Maven的插件401錯誤

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

按照這個似乎戰爭文件的位置不被傳遞到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> 

我不知道究竟是怎麼了?here.any幫助在這方面會有所幫助。

+0

嘗試在settings.xml中的'id'字段中放置'localhost'而不是'Tomcat6.x'。 – Tarlog

+0

@Tarlog:使用localhost的概念是什麼?因爲使用這個值解決了這個問題,所以我想知道 –

+0

我會添加一個明確的答案:) – Tarlog

回答

4

您需要將憑據從settings.xml映射到您的pom.xml中的服務器配置。

在你的情況下,這是完成的,但設置了<id>服務器的元素,以匹配來自pom.xml的服務器的主機名。

既然你指的是localhost,那麼這個ID也必須是localhost。 更改主機名時,還必須更新settings.xml。

+0

感謝Tarlog的描述:) –

2

它在plugin configuration docs:在Maven的設置server/id標籤必須在你的POM文件的configuration/server值相匹配,即在POM文件放在<server>Tomcat6.x</server>

有與在POM文件的tomcat-maven-plugin進入一些其他的小問題:

  1. 你缺少的<version>1.1</version>標籤,
  2. /html後綴在Tomcat管理器URL是不必要的(參見默認值爲<url>標籤)。
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:部署或tomcat6中:部署

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

我建議你使用這個插件:

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

這是一個與Tomcat7非常有幫助。我有與mojo <groupId>org.codehaus.mojo</groupId> 相同的問題,但現在,使用Cargo插件,部署運行平滑如絲。