tomcat7 maven插件部署失败

时间:2012-11-06 10:46:35

标签: tomcat maven deployment tomcat7

我在使用tomcat作为服务安装部署到远程计算机时遇到了问题。 我的tomcat用户如下:

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

</tomcat-users>

我的settings.xml是:

<settings>
<pluginGroups>
<pluginGroup>org.apache.tomcat.maven</pluginGroup>
</pluginGroups>
<servers>
<server>
  <id>tomcat7</id>
  <username>admin</username>
  <password>admin</password>
</server>

</servers>

</settings>

我的pom.xml有以下内容:

            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <configuration>
                    <server>tomcat7</server>
                    <url>http://localhost:8081/manager/text</url>
                    <warFile>target/editor-${project.version}.war</warFile>
                </configuration>

我继续在maven控制台的输出上获得401 Unauthorized。你能告诉我我做错了什么吗?                 

4 个答案:

答案 0 :(得分:6)

以下方式对我有用。

  1. 请更改您的pom.xml以包含

    <project>
        ...
        <build>    
            <plugins>    
            ....
                <plugin>
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat7-maven-plugin</artifactId>
                    <version>2.1</version>
                    <configuration>
                        <url>http://localhost:8080/manager/text</url>
                        <server>my-tomcat</server>
                        <path>/myapp</path>
                    </configuration>
                </plugin>
            </plugins>
            ...
        </build>
        ...
    </project>
    
  2. 确保您的Tomcat 7服务器在TOMCAT_HOME/conf/tomcat-users.xml上有以下行:

    <!-- Role to manage WAR files via HTML /manager. The name should be as is! -->
    <role rolename="manager-gui"/>
    <!-- Role to manage WAR files via script like Maven. The name should be as is! -->
    <role rolename="manager-script"/>
    
    <!-- One user cannot have manager-gui and manager-script roles -->
    <user username="managerGui" password="managerPwd" roles="manager-gui"/>
    <user username="manager" password="managerPwd" roles="manager-script"/>
    
  3. 配置USER_HOME/.m2/settings.xml以包含密码。

    <settings>
        ...
        <servers>
            ...
            <server>
                <id>my-tomcat</id>
                <username>manager</username>
                <password>managerPwd</password>
            </server>
        </servers>
    
    </settings>
    
  4. 使用mvn tomcat7:redeploy

  5. 进行部署

    详细了解http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html

答案 1 :(得分:3)

尝试使用-x -e运行mvn 然后你会看到什么样的信息发送到服务器。我的猜测是服务器没有获得用户名/通行证。这意味着配置文件有问题,即:settings.xml

tomcat7-maven-plugin如何知道settings.xml的位置?

编辑:查看此which-maven-settings-xml-files

elek 提供了用-X运行mvn并在开始时看到 “从.user / .m2 / settings.xml中读取用户设置..

答案 2 :(得分:1)

mvn tomcat7:redeploy -Dtomcat.username=tomcatscript -Dtomcat.password=s3cret

也可以。

答案 3 :(得分:0)

您应该在tomcat-users.xml中声明所有角色:

<role rolename="tomcat"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="admin"/>
<role rolename="manager-script"/>

HIH