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

4

我正在使用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个回答

5

文档提到远程部署命令应该发送到manager/text的URL,见在远程部署新应用程序

通过将配置更改为该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>

好的,我已经做到了。我目前的问题是,当我通过eclipse启动tomcat时,文件tomcat-users.xml会被重新定义,我插入文件中的数据会丢失。当我在启动tomcat后重新打开此文件时,文件的内容与我保存的完全不同。 - Kleber Mota
1
请在资源管理器树中检查“服务器”部分,这些是每次部署时覆盖服务器的Tomcat文件。尝试直接编辑它们。 - Angular University

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

0

导致问题的根本原因是在tomcat-users.xml文件中没有指定“manager-script”角色的用户

<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"/>

因此,除了指定一个manager-script角色外,您还需要创建一个实际的manager-script用户,并将该用户插入到Web应用程序POM中。 我的环境是IntelliJ和Maven项目。

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.3-SNAPSHOT</version>
                <configuration>
                    <url>http://localhost:8080/manager/text</url>
                    <server>TomcatServer</server>
                    <username>tcat-script</username>
                    <password>psswrd</password>
                </configuration>
            </plugin>
        </plugins>
    </build>

祝你好运!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接