maven 2.2.1 Tomcat 7无法调用Tomcat管理器:401

时间:2012-07-06 11:43:21

标签: tomcat maven

我尝试在tomcat 7上部署新的maven项目。我得到了

[INFO] Building war: C:\Workspace2\sw\webapp\target\mkyongweb-core-1.0.war
[INFO] [tomcat:deploy {execution: default-cli}]
[INFO] Deploying war to http://localhost:8080/mkyongweb-core
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Cannot invoke Tomcat manager

Embedded error: Server returned HTTP response code: 401 for URL: http://localhost:8080/manager/deploy?path=%2Fmkyongweb-core&war=

Tomcat的users.xml中

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

%MAVEN-HOME%/ CONF / settings.xml中

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

和我的pom.xml(tomcat6)

   <build>
        <plugins>
            <!-- Maven Tomcat Plugin -->
            <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>tomcat-maven-plugin</artifactId>
            <version>1.0</version>
            <configuration>
            <server>tomcat7</server>
            <url>h ttp://loca lhost:8080/manager</url>                  
            <path>/mkyongWebApp</path>
            </configuration>
        </plugin>           
            <!-- Maven compiler plugin -->
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>

        </plugins>
    </build>

此pom.xml使错误401

  

[INFO]无法调用Tomcat管理器嵌入式错误:服务器返回   HTTP响应代码:401为URL:   http://localhost:8080/manager/deploy?path=%2Fmkyongweb-core&war=

下面的插件会出现同样的错误

  <plugins>
        <!-- Maven Tomcat Plugin -->
        <plugin>            
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat6-maven-plugin</artifactId>
        <version>2.0-beta-1</version>
        <configuration>             
            <server>tomcat7</server>
            <url>http://localhost:8080/manager</url>
            <path>/mkyongWebApp</path>
        </configuration>
    </plugin>           

        <!-- Maven compiler plugin -->
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>

    </plugins>

2 个答案:

答案 0 :(得分:0)

你应该使用apache maven tomcat插件而不是codehaus tomcat-maven-plugin。

http://tomcat.apache.org/maven-plugin-2/

如codehaus网站上所述。

答案 1 :(得分:0)

您必须提供服务器(tomcat 7)

的引用
     <plugin>
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>tomcat-maven-plugin</artifactId>
         <configuration>
            <server>tomcat7</server>
            <url>http://localhost:8080/manager/html</url>
         </configuration>
        </plugin>