简体   繁体   English

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

[英]Error 403 when try to deploy a maven project with tomcat-maven-plugin

I am trying deploy my project to tomcat7 using the Eclipse IDE, and I facing this 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

My pom.xml have this configuration:我的 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>

My tomcat-users.xml is that:我的 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>

Anyone can point me what I doing wrong?任何人都可以指出我做错了什么?

the documentation mentions that the remote deployment commands should be sent to url manager/text , see here in Deploy A New Application Remotely . 文档提到远程部署命令应该发送到url manager/text ,请参阅远程部署新应用程序

by changing the configuration to that url instead, it should work: 通过将配置更改为该URL,它应该工作:

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

Also Tomcat has several pre-defined roles for doing certain tasks, try adding role manager-script : Tomcat还有几个用于执行某些任务的预定义角色,请尝试添加角色manager-script

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

I changed the Server location configuration of the tomcat within the eclipse configuration panel. 我在eclipse配置面板中更改了tomcat的服务器位置配置。 In this way eclipse uses directly the configuration of your tomcat installation instead of the workspace metadata. 这样,eclipse直接使用tomcat安装的配置而不是工作空间元数据。 After conducting all steps according to this question and similar questions and answers this step finally solved the problem for me. 根据这个问题和类似的问题和答案进行所有步骤后,这一步最终解决了我的问题。 Problem prerequesites: Eclipse Luna, Maven 3.1, Dynamic-Web-Project, maven-war-plugin, tomcat 7 问题的先决条件:Eclipse Luna,Maven 3.1,Dynamic-Web-Project,maven-war-plugin,tomcat 7

Following picture shows the appropriate configuration which worked for me and solved the same problem of OP. 下图显示了适合我的配置并解决了OP的相同问题。

Eclipse Tomcat服务器配置面板(双击服务器视图中的服务器名称即可访问)

The underlying cause for me was leaving out a designated "manager-script" role user in tomcat-users.xml我的根本原因是在 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"/>

So in addition to designating a manager-script role you need to create an actual manager-script user and this is the user you plug into the Web-apps POM.因此,除了指定 manager-script 角色之外,您还需要创建一个实际的 manager-script 用户,这是您插入 Web-apps POM 的用户。 My environment is IntelliJ and Maven project.我的环境是 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>

Good luck!祝你好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么tomcat-maven-plugin尝试部署到错误的URL? - Why is tomcat-maven-plugin trying to deploy to the wrong URL? 当我尝试将Maven项目部署到tomcat时出现套接字写入错误 - Socket write error when I try to deploy maven project to tomcat tomcat-maven-plugin 401。 显示不同的端口号时出错 - tomcat-maven-plugin 401 . Error showing different port number 带有多个模块的tomcat-maven-plugin和pluginManagement - tomcat-maven-plugin and pluginManagement with multiple module Maven无法下载tomcat-maven-plugin快照 - Maven is failing to download the tomcat-maven-plugin snapshot Maven:在哪里为tomcat-maven-plugin添加生成的资源? - Maven: Where to put generated resources for tomcat-maven-plugin? 无法执行目标org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy(default-cli) - Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy (default-cli) GWT 项目中的 tomcat-maven-plugin。 org.codehaus.mojo 和 org.apache.tomcat.maven 插件有什么区别 - tomcat-maven-plugin in GWT project. What is the difference between: org.codehaus.mojo and org.apache.tomcat.maven plugin 将我的javaagent传递给tomcat-maven-plugin而不是Tomcat服务器 - pass my javaagent to tomcat-maven-plugin NOT Tomcat Server tomcat-maven-plugin 抛出 java.lang.ClassNotFoundException: - tomcat-maven-plugin throws java.lang.ClassNotFoundException:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM