【问题标题】:tomcat-maven-plugin 403 errortomcat-maven-plugin 403错误
【发布时间】:2011-03-23 19:21:53
【问题描述】:

当我使用 mvn tomcat:deploy of tomcat-maven-plugin 时出现 403 错误:

无法在项目 my-webapp 上执行目标 org.codehaus.mojo:tomcat-maven-plugin:1.0:deploy (default-cli):无法调用 Tomcat 管理器:服务器返回 HTTP 响应代码:403 用于 URL:@987654321 @

我认为是因为 null 战争参数。但是为什么它为空???

在 pom.xml 中有:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>tomcat-maven-plugin</artifactId>

  <configuration>
    <warFile>target\my-webapp.war</warFile>
    <server>myserver</server>
    <url>http://localhost:8080/manager/text</url>
    <path>/dms</path>
  </configuration>
</plugin>

【问题讨论】:

    标签: maven tomcat maven-tomcat-plugin


    【解决方案1】:

    你应该使用 /text:

    http://localhost:8080/manager/text

    并且还添加到用户角色管理脚本

    【讨论】:

    • 非常感谢我的朋友......你为我结束了一段伟大的旅程
    • 这个。这是有效的解决方案。为tomcat 7.0.53工作。
    • 仅在使用 server:8080 时为我工作 - 根本不需要使用 /manager
    【解决方案2】:

    您使用的是 tomcat 7,您应该将插件配置保留在 pom.xml 中,如下所示:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>tomcat-maven-plugin</artifactId>
        <configuration>
            <url>http://localhost:8080/manager/html</url>
            <server>tomcat</server>
            <path>/finance</path>
        </configuration>
    </plugin>
    

    我已经尝试过版本配置,如上面的示例,但它对我不起作用。 在settings.xml中应该有服务器的配置,与pom.xml中的值匹配

    <settings>
        <servers>
            <server>
                <id>tomcat</id>
                <username>admin</username>
                <password>admin</password>
            </server>
        </servers>
    </settings>
    

    因此,mvn tomcat:deploy 或 mvn tomcat:redeploy(如果您已经部署了应用程序)或 mvn tomcat:run(tomcat 关闭)应该可以工作。

    【讨论】:

    • 结尾的“/html”是关键——我需要它才能让它在 Tomcat 7 上也能正常工作。
    • 对于某些人来说,tomcat 7 似乎需要一个 URL,例如:localhost:8080/manager/text>。有关相关问题,请参阅 this answer
    【解决方案3】:

    /manager 应用程序默认受用户名/密码保护。如果您输入http://localhost:8080/manager,您还将被要求提供安全凭证。首先在 Tomcat 中创建/启用用户:在取消或几次失败尝试后,Tomcat 将在错误屏幕上提供帮助。然后按照here 的说明在tomcat-maven-plugin 中使用这些凭据:

    在你的 pom.xml 中添加一个插件配置块:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>tomcat-maven-plugin</artifactId>
        <configuration>
                <server>myserver</server>
        </configuration>
    </plugin>
    

    将相应的服务器块添加到您的 settings.xml:

    <server>
        <id>myserver</id>
        <username>myusername</username>
        <password>mypassword</password>
    </server>
    

    【讨论】:

      【解决方案4】:

      您只需要通过添加“/html”来更改网址,这样它就会像这样http://localhost:8080/manager/html 并且宾果游戏就可以了 希望有所帮助

      【讨论】:

      • 感谢@amira。你的这个强调让我的问题解决了!谢谢
      【解决方案5】:

      对于 Tomcat7,在 tomcat-users.xml 中你还需要角色名 ma​​nager-script

      <role rolename="manager-gui"/>
      <role rolename="manager-script"/>
      <user username="tomcat" password="s3cret" roles="manager-script,manager-gui"/>
      

      在项目的 POM.xml 中

      <plugin>
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>tomcat-maven-plugin</artifactId>
         <configuration>
              <url>http://localhost:8080/manager/text</url>
              <server>myserver</server>
              <path>/sw</path>
         </configuration>
      </plugin>
      

      和maven的settings.xml:

      <servers>
       <server>
        <id>myserver</id>
        <username>tomcat</username>
        <password>s3cret</password>
       </server>
      </servers>
      

      【讨论】:

      • 虽然代码很受欢迎,但它应该始终有一个附带的解释。这不必很长,但在意料之中。
      • 终于!谢谢你:)
      【解决方案6】:

      有几个步骤必须确保已完成。这可能是一个真正的黑洞。

      如果您使用的是 org.codehaus.mojo 中的 tomcat-maven-plugin,则必须使用此配置:

      <configuration>
          <url>http://localhost:8080/manager/text</url>
          <warFile>your_war_filename.war</warFile>
          <server>server_name_on_settingsxml</server>
      </configuration>
      

      请确保您在 maven settings.xml 上定义了“server_name_on_settingsxml”服务器凭据。 使用 mvn tomcat:deploy (必须使用这个 'tomcat' 前缀),这是部署时读取上述配置的唯一方法。

      但是,如果您使用来自 org.apache.tomcat.maven 的 tomcat7-maven-plugin,则必须使用 mvn tomcat7:deploy。 'tomcat7' 前缀将从插件中读取配置:

              <plugin>
                  <groupId>org.apache.tomcat.maven</groupId>
                  <artifactId>tomcat7-maven-plugin</artifactId>
      

      我使用的是 tomcat:deploy,并且我在 pom.xml 上定义了 tomcat7-maven-plugin。所以,Maven 部署从未读取我的配置标签...

      如果您确保正确定义了用户名和密码,并且在部署时使用了正确的插件,那么它将起作用。

      【讨论】:

        【解决方案7】:

        如果您尝试使用 codehouse tomcat 插件 1.1 版在 Tomcat 7 服务器上部署,您可能会遇到 403 错误。 1.1 版尚不支持 Tomcat 7。

        如果你使用的是 Tomcat 7,你应该使用 Cargo。

        【讨论】:

          【解决方案8】:

          如果您使用的是 Tomcat 7:

          1. 更改 pom.xml 中的配置以使用 Tomcat 7 版本 插件

            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                    <url>http://127.0.0.1:8080/manager/html</url>
                    <server>TomcatServer</server>
                    <path>/your_context</path>
                    <username>some_user_name</username>
                    <password>some_password</password>
                </configuration>
            </plugin>
            

          注意 和 值 - 它们与 Tomcat 6 的值不同。

          1. 别忘了把“tomcat:deploy”改成“tomcat7:deploy” 您的脚本或 Eclipse 中的外部工具配置启动器。
          2. 将服务器配置添加到您的 settings.xml,通常位于 .m2 文件夹下
          <server>
              <id>TomcatServer</id>
              <username>some_user_name</username>
              <password>some_password</password>
          </server>
          
          1. 如果您需要其他选项,例如部署位于 非标准文件夹,请访问:Tomcat 7 Maven Plugin

          【讨论】:

            【解决方案9】:

            我发现我必须使用以下字符串而不是“html”:

            http://localhost:8080/manager/text
            

            【讨论】:

              【解决方案10】:

              这也是可能的:

              <plugin>
                 <groupId>org.codehaus.mojo</groupId>
                 <artifactId>tomcat-maven-plugin</artifactId>
                  <configuration>
                      <server>myserver</server>
                      <username>admin</username>
                      <password>admin</password>
                  </configuration>
              </plugin>
              

              【讨论】:

              • 这里的问题是您将部署 .pom 文件以及您的凭据。 settings.xml 将不会被部署。
              【解决方案11】:

              如果你使用Tomcat 7,你需要参考tomcat插件中的urlhttp://localhost:8080/manager/html

              http://mojo.codehaus.org/tomcat-maven-plugin/examples/deployment-tomcat7.html

              <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>tomcat-maven-plugin</artifactId>
                <version>1.2-SNAPSHOT</version>
                <configuration>
                  <url>http://localhost:8080/manager/html</url>
                </configuration>
              </plugin>
              

              【讨论】:

                【解决方案12】:

                如果您使用的是版本 7,则有一个问题:默认情况下不启用对 /manager/text 资源的访问。

                您必须创建一个角色为 mananger-script 的用户,正如 documentation 中所说的那样

                It would be quite unsafe to ship Tomcat with default settings that allowed anyone
                on the Internet to execute the Manager application on your server.
                Therefore, the Manager application is shipped with the requirement that anyone
                who attempts to use it must authenticate themselves, using a username and
                password that have the role manager-script associated with them.
                Further, there is no username in the default users file
                ($CATALINA_BASE/conf/tomcat-users.xml) that is assigned this role.
                Therefore, access to the Manager application is completely disabled by default.
                
                To enable access to the Manager web application, you must either create a new
                username/password combination and associate the role name manager-script with it,
                or add the manager-script role to some existing username/password combination.
                

                希望对你有帮助:)

                【讨论】:

                  【解决方案13】:

                  我曾经遇到过同样的错误,您只需要确保 tomcat-users.xml 文件包含角色为(经理、经理-gui、管理员、经理-脚本)的用户(在我的情况下为管理员)。

                  我在 ubuntu 上有 tomcat 7、maven 3。

                  【讨论】:

                    【解决方案14】:

                    您只需在 config 文件夹中的 tomcat-users.xml 中将 manager-script 和 manager 角色添加到您的 tomcat 用户。 在 Tomcat 7 中,您必须为不同的管理器 GUI 访问指定不同的角色,在这种情况下,这些访问是文本。最后,对于文本界面,您必须使用管理器脚本角色。

                    【讨论】:

                      【解决方案15】:

                      您可能应该检查 ~/.m2/settings.xml 中的配置文件,该文件必须具有以下结构:

                      <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
                        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                                            http://maven.apache.org/xsd/settings-1.0.0.xsd">
                        <localRepository/>
                        <interactiveMode/>
                        <usePluginRegistry/>
                        <offline/>
                        <pluginGroups/>
                        <servers/>
                        <mirrors/>
                        <proxies/>
                        <profiles/>
                        <activeProfiles/>
                      </settings>
                      

                      之后,您应该确保您的服务器配置对于您的项目是正确的,例如:

                        <servers>
                           <server>
                              <id>mytomcat</id>
                              <username>test</username>
                              <password>test</password>
                           </server>
                        </servers>
                      

                      稍后运行 mvn tomcat:deploy。请记住,您也可以运行 tomcat:deploy -X 来查看调试。

                      【讨论】:

                        【解决方案16】:

                        此解决方案适用于“Apache”Tomcat7 插件: 正如之前已经提到的,您需要将“/text”添加到 url 的末尾

                        <plugin>
                        <groupId>org.apache.tomcat.maven</groupId>
                        <artifactId>tomcat7-maven-plugin</artifactId>
                        <version>2.2</version>
                        <configuration>
                            <port>8080</port>
                            <path>/deployPath</path>
                            <url>http://localhost:8080/manager/text</url>
                            <server>TomcatServer</server>
                        </configuration>
                        

                        配置位于 .m2 文件夹内的“settings.xml”

                        <servers>
                            <server>
                                <id>TomcatServer</id>
                                <username>script-admin</username>
                                <password>password</password>
                            </server>
                        </servers>
                        

                        由于您使用的是 Tomcat 7,最重要的是您应该为“manager-script”角色创建一个不同的用户,正如文档中提到的那样!

                        <role rolename="manager-script"/>
                        <user username="tomcat" password="password" roles="manager-script"/>
                        

                        【讨论】:

                          【解决方案17】:

                          如果你遇到用户名和密码的问题请不要着急,在tomcat目录中有一个文件名为tomcat-user.xml,去那里查看名称和密码属性,当提示询问用户名和密码时使用密码。

                          如果还是打不开apache主页做一件事,在tomcat目录下还有一个文件名为server.xml去把8080端口改成这个

                          【讨论】:

                            【解决方案18】:

                            如果您使用带有插件 m2eclipse 的 Eclipse,并且在尝试这些解决方案后仍然出现此错误,可能是因为该插件没有包含管理器。您应该单独下载 Tomcat 并配置 Eclipse 以使用它(查看此链接:tomcat-maven-plugin: Server returned HTTP response code: 403

                            【讨论】:

                            • 好的。我修改了它。现在好点了吗? :)
                            【解决方案19】:

                            从 tomcat6 到 tomcat7 回顾:

                            1. 在 tomcat-user.xml 中添加角色
                            2. 在您的网址中添加 /text 或 /html
                            3. 更改插件版本

                              <groupId>org.apache.tomcat.maven</groupId> 
                              <artifactId>tomcat7-maven-plugin</artifactId> 
                              <version>2.2</version>
                              
                            4. 将选项 tomcat:deploy 更改为 tomcat7:deploy

                            【讨论】:

                              【解决方案20】:

                              我在 服务器返回 HTTP 响应代码:400 上花费了三天多的时间,同时尝试将 Web 应用程序部署到与 Netbeans 捆绑的 Tomcat Server 8.0 上。当我在命令行上使用mvn tomcat7:deploy 时,一切正常,但通过 Netbeans IDE 没有成功。我在 POM.xml 中设置了 tomcat maven 插件

                              <plugin>
                                  <groupId>org.apache.tomcat.maven</groupId>
                                  <artifactId>tomcat7-maven-plugin</artifactId>
                                  <configuration>
                                      <url>http://localhost:8080/manager/text</url>
                                      <server>tomcat</server>
                                  </configuration>
                              </plugin>
                              

                              在 .m2/conf/settings.xml 中为 Maven 加上服务器记录,

                              <settings>
                                  <servers>
                                      <server>
                                          <id>tomcat</id>
                                          <username>admin</username>
                                          <password>admin</password>
                                      </server>
                                  </servers>
                              </settings>
                              

                              甚至在 tomcat-users.xml 中合适的 tomcat 用户

                              <role rolename="manager-gui"/>
                              <role rolename="manager-script"/>
                              <user username="tomcat" password="tomcat" roles="manager-script,manager-gui"/>
                              

                              但仍然没有成功。根本原因是我们公司和 Netbeans 设置中使用的代理服务器。 在 Netbeans 中,转到工具 -> 选项,然后在常规选项卡上,使用手动代理设置而不是系统代理设置(即使系统代理设置有效)。它帮助了我,现在我可以直接从 Netbeans 在 Tomcat 8 上部署 Web 应用程序。当您只使用本地主机服务器时,您也可以设置无代理。我的问题的根本原因是在默认网络浏览器中设置了错误的代理,这是选项系统代理设置的来源。

                              【讨论】:

                                【解决方案21】:

                                我也收到 403 错误,但只有当我通过 Apache 2 连接时。当我使用端口 8080 并直接部署到 tomcat 时,它可以工作。所以:尝试将端口 8080 添加到 URL

                                我仍在试图弄清楚为什么它不能通过 Apache 工作。我正在使用ProxyPass / ajp://localhost:8009/

                                <Location "/manager" >
                                     Order allow,deny
                                     Allow from 62.245.147.202
                                     Satisfy Any
                                   </Location>
                                

                                【讨论】:

                                  猜你喜欢
                                  • 2011-11-12
                                  • 2014-06-04
                                  • 2013-03-29
                                  • 1970-01-01
                                  • 1970-01-01
                                  • 1970-01-01
                                  • 2012-02-16
                                  • 1970-01-01
                                  • 2012-07-12
                                  相关资源
                                  最近更新 更多