尝试使用tomcat-maven-plugin部署maven项目时出现错误403

时间:2014-04-20 12:51:34

标签: java eclipse maven tomcat

我正在尝试使用Eclipse IDE将项目部署到tomcat7,我遇到了这个错误:

Uploading: http://localhost:8080/manager/html/deploy?path=%2Fexample
Uploaded: http://localhost:8080/manager/html/deploy?path=%2Fexample (13855 KB at 61573.5 KB/sec)

[ERROR] Tomcat return http status error: 403, Reason Phrase: Forbidden
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.259s
[INFO] Finished at: Sun Apr 20 09:44:18 GMT-03:00 2014
[INFO] Final Memory: 13M/223M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy (default-cli) on project example: Tomcat return http status error: 403, Reason Phrase: Forbidden: <html><head><title>Apache Tomcat/7.0.50 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 403 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>Access to the specified resource has been forbidden.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.50</h3></body></html> -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[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 read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

我的pom.xml有这样的配置:

  <build>
  <plugins>
            <plugin>
              <groupId>org.apache.tomcat.maven</groupId>
              <artifactId>tomcat7-maven-plugin</artifactId>
              <version>2.2</version>
              <configuration>
                  <url>http://localhost:8080/manager/html</url>
                  <server>TomcatServer</server>
                  <path>/example</path>
                  <username>klebermo</username>
                  <password>[password]</password>
              </configuration>
            </plugin>
    </plugins>
    </build>

我的tomcat-users.xml就是:

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
  <role rolename="manager"/>
  <role rolename="admin"/>
  <user username="klebermo" password="[password]" roles="admin,manager"/>
</tomcat-users>

任何人都可以指出我做错了什么?

3 个答案:

答案 0 :(得分:5)

文档提到应将远程部署命令发送到网址manager/text,请参阅Deploy A New Application Remotely中的内容。

通过将配置更改为该URL,它应该起作用:

<configuration>
    <url>http://localhost:8080/manager/text</url>
    ...
</configuration>

Tomcat还有几个预先定义的角色来执行某些任务,尝试添加角色manager-script

<tomcat-users>
  <user username="tomcat" password="[password]" 
       roles="admin,manager,manager-script"/>
</tomcat-users>

答案 1 :(得分:2)

我在eclipse配置面板中更改了tomcat的服务器位置配置。 这样,eclipse直接使用tomcat安装的配置而不是工作空间元数据。根据这个问题和类似的问题和答案进行所有步骤后,这一步最终解决了我的问题。 问题的先决条件:Eclipse Luna,Maven 3.1,Dynamic-Web-Project,maven-war-plugin,tomcat 7

下图显示了适合我的配置并解决了OP的相同问题。

Eclipse Tomcat Server Config Panel (reachable by double-click on the server name within the server view

答案 2 :(得分:0)

对我来说,根本原因是在tomcat-users.xml中遗漏了指定的“管理员脚本”角色用户

#include "function.h" 
//^ this should be "-quoted not <-quoted because it's not a system header
//int funtion(void); //this declaration is redundant
//#include <stdio.h> isn't needed here because you're not directly calling
//functions from stdio

int main (void)
{
     function();
     return(0);
}

因此,除了指定管理员脚本角色之外,您还需要创建一个实际的管理员脚本用户,这是您插入Web应用程序POM的用户。 我的环境是IntelliJ和Maven项目。

<role rolename="manager-gui"/>
  <role rolename="manager-script"/>
  <!-- <user username="tomcatadmin" password="s3cret" roles="manager-gui"/> -->
  <user username="tcat-gui" password="asdf" roles="manager-gui"/>
    <user username="tcat-script" password="psswrd" roles="manager-script"/>

祝你好运!