不能做mvn tomcat:因为http响应405而部署

时间:2013-01-20 17:49:22

标签: maven tomcat tomcat7 maven-plugin

我正在运行Tomcat 7作为Windows服务。 我想在我的项目根目录中执行mvn:tomcat部署。

但是这个错误一直出现,你能帮我解决这个问题吗?

[INFO] Deploying war to http://localhost:8080/opendata
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.493s
[INFO] Finished at: Sun Jan 20 18:48:30 CET 2013
[INFO] Final Memory: 15M/39M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy
(default-cli) on project opendata: Cannot invoke Tomcat manager: Server returned
 HTTP response code: 405 for URL: http://localhost:8080/manager/deploy?path=%2Fo
pendata&war= -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionE
xception

我的pom文件中有以下部分:

<build>
        <finalName>opendata</finalName>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>tomcat-maven-plugin</artifactId>
                <configuration>
                    <server>myserver</server>
                </configuration>
                <version>1.1</version>
            </plugin>

            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.0.2</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

2 个答案:

答案 0 :(得分:2)

要让它发挥作用需要两件事;

  • tomcat用户,其tomcat-users.xml中包含角色manager-script
  • 指定部署到以经理/文本结尾的内容的网址。

就是这样。请参阅下面的pom.xml示例conf。并且不要忘记使用tomcat7:redeploy,这样您就不必循环取消部署/部署。

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <url>http://your-server:8080/manager/text</url>
        <username>a-username</username>
        <password>a-password</password>
        <path>/a-path</path>
    </configuration>
</plugin>

答案 1 :(得分:1)

我今天遇到了类似的问题--404错误可能是由Tomcat不接受PUT请求引起的。这可以通过配置Tomcat的web.xml(通常在%TOMCAT%\conf\web.xml中找到)并添加以下init-param来实现:

<init-param>
    <param-name>readonly</param-name>
    <param-value>false</param-value>
</init-param>

您可能还需要将admin用户添加到tomcat-users.xml。有关详细信息,请参阅here