Java 尝试使用tomcat maven插件部署maven项目时出现错误403

Java 尝试使用tomcat maven插件部署maven项目时出现错误403,java,eclipse,maven,tomcat,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

我正在尝试使用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
上传:http://localhost:8080/manager/html/deploy?path=%2Fexample
上载:http://localhost:8080/manager/html/deploy?path=%2Fexample (每秒61573.5 KB时为13855 KB)
[错误]Tomcat返回http状态错误:403,原因短语:禁止
[信息]------------------------------------------------------------------------
[信息]生成失败
[信息]------------------------------------------------------------------------
[信息]总时间:6.259秒
[信息]完成时间:2014年4月20日星期日09:44:18 GMT-03:00
[信息]最终内存:13M/223M
[信息]------------------------------------------------------------------------
[错误]无法在项目上执行目标org.apache.tomcat.maven:tomcat7 maven插件:2.2:deploy(默认cli)示例:tomcat返回http状态错误:403,原因短语:禁止:apache tomcat/7.0.50-错误报告http状态403-
键入状态报告

消息

说明已禁止对指定资源的访问。


Apache Tomcat/7.0.50->[帮助1] [错误] [错误]要查看错误的完整堆栈跟踪,请使用-e开关重新运行Maven。 [错误]使用-X开关重新运行Maven以启用完整调试日志记录。 [错误] [错误]有关错误和可能的解决方案的更多信息,请阅读以下文章: [错误][帮助1]http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
My 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>

org.apache.tomcat.maven
tomcat7 maven插件
2.2
http://localhost:8080/manager/html
TomcatServer
/范例
克莱伯莫
[密码]
我的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>


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

文档提到远程部署命令应该发送到url
manager/text
,请参见中的此处

通过将配置改为该url,它应该可以工作:

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

我在eclipse配置面板中更改了tomcat的服务器位置配置。 通过这种方式,eclipse直接使用tomcat安装的配置,而不是工作区元数据。根据这个问题和类似的问题和答案进行所有步骤后,这个步骤最终为我解决了问题。 问题预告网站:EclipseLuna、Maven 3.1、动态Web项目、Maven war插件、Tomcat7

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


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

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

因此,除了指定经理脚本角色外,您还需要创建一个实际的经理脚本用户,这就是您插入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>

org.apache.maven.plugins
maven编译器插件
3.8.1
1.8
1.8
org.apache.tomcat.maven
tomcat7 maven插件
2.3-2
http://localhost:8080/manager/text
TomcatServer
tcat脚本
psswrd

祝你好运

好的,我做到了。我当前的问题是,当我启动tomcat(通过eclipse)时,文件tomcat-users.xml被重新定义,而我在文件中插入的数据丢失了。启动tomcat后重新打开此文件时,该文件的内容与我保存的内容完全不同。请检查资源管理器树中的
Servers
部分,这些是在每次部署时覆盖服务器的tomcat文件。试着直接编辑它们。
<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>