eclipse 如何修复“无法调用 Tomcat 管理器:服务器返回 HTTP 响应代码:403”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19340197/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 21:15:13  来源:igfitidea点击:

How to fix "Cannot invoke Tomcat manager: Server returned HTTP response code: 403 "

eclipsemavenjakarta-eetomcat

提问by MoienGK

i am using maven, eclipse and tomcat7. i am trying to deploy my web application in tomcat with clean tomcat:deploycommand , but every time i get this error :

我正在使用 maven、eclipse 和 tomcat7。我正在尝试使用clean tomcat:deploy命令在 tomcat 中部署我的 Web 应用程序,但每次出现此错误时:

[ERROR] Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy (default-cli) on project azraspina: Cannot invoke Tomcat manager: Server returned HTTP response code: 403 for URL: http://localhost:8080/manager/html/deploy?path=%2Fazraspina&war= -> [Help 1]

this is the plugin part of my pom.xml :

这是我的 pom.xml 的插件部分:

<plugins>
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>tomcat-maven-plugin</artifactId>
        <configuration>
            <username>admin</username>
            <password>admin</password>
            <server>raspinaserver</server>
            <path>/azraspina</path>
            <url>http://localhost:8080/manager/html</url>
        </configuration>
    </plugin>

</plugins>

and this is part of my tomcat-users.xml :

这是我的 tomcat-users.xml 的一部分:

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

so far i have tried almost everything on the web! i have added the credential part of pom.xml to setting.xml of maven but it didn't solve the problem.i also tried to use "tomcat7-maven-plugin" but still no luck. i even tried hitting my head over the cement wall ahap(as hard as possible) but i am still alive so no luck there either. so, would you please help me to solve this problem? thank you

到目前为止,我已经尝试了几乎所有网络上的东西!我已将 pom.xml 的凭证部分添加到 maven 的 setting.xml 但它没有解决问题。我也尝试使用“tomcat7-maven-plugin”但仍然没有运气。我什至试着把我的头撞到水泥墙上(尽可能用力)但我还活着,所以那里也没有运气。所以,你能帮我解决这个问题吗?谢谢你

回答by user944849

If you are deploying to Tomcat 7, you might consider using the Tomcat 7 Maven plugin from Apacheinstead of the Codehaus version.

如果您要部署到 Tomcat 7,您可能会考虑使用ApacheTomcat 7 Maven 插件而不是 Codehaus 版本。

Typically, credentials do not go into the plugin configuration in the POM, as the POM ends up in an artifact repository and is usually shared with other developers. Credentials go in the settings.xml <servers>element, then you configure the plugin to reference that server. This is what the Tomcat 7 plugin usage docsand the Codehaus tomcat plugindescribe.

通常,凭据不会进入 POM 中的插件配置,因为 POM 最终位于工件存储库中,并且通常与其他开发人员共享。凭据进入 settings.xml<servers>元素,然后配置插件以引用该服务器。这是Tomcat 7 插件使用文档Codehaus tomcat 插件所描述的。

So, your settings.xml:

因此,您的 settings.xml:

....
<servers>
  <server>
      <id>raspinaserver</id>
      <username>admin</username>
      <password>admin</password>
  </server>
</servers>
...

And the plugin config:

和插件配置:

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

回答by Angel

I think that the problem could be in the manager URL. Try this on your pom.xml:

我认为问题可能出在经理 URL 中。在你的pom.xml上试试这个:

<url>http://localhost:8080/manager/html</url>

instead of :

代替 :

<url>http://localhost:8080/manager</url>

I couldn't find documentation about those URLs (surely exists), but anyway it works for me to deploy to apache-tomcat-6.0.39using tomcat-maven-plugin v1.1

我找不到有关这些 URL 的文档(肯定存在),但无论如何它对我来说可以使用tomcat-maven-plugin v1.1部署到apache-tomcat-6.0.39

That's a second possible problem in your pom.xml : you haven't specified which version of the plugin to use. It can work ... but it's error prone. Maven even warns about these things. I use this on my pom.xml :

这是您的 pom.xml 中的第二个可能的问题:您尚未指定要使用哪个版本的插件。它可以工作......但它很容易出错。Maven 甚至对这些事情发出警告。我在我的 pom.xml 上使用它:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>tomcat-maven-plugin</artifactId>
  <version>1.1</version>
  <configuration>
    <url>http://localhost:8080/manager</url>
    <server>MyTomcat</server>
    <path>/agalindo-webui</path>
  </configuration>
</plugin>

There I have specified the server like user944849sugests on my settings.xml (~/.m2/settings.xml), like this:

我在 settings.xml ( ~/.m2/settings.xml)上指定了像user944849sugests这样的服务器,如下所示:

<settings>
  <servers>
    <server>
      <id>MyTomcat</id>
      <username>myusername</username>
      <password>mypassword</password>
    </server>
  </servers>
  <!-- .. -->
</settings>

Hope it helps,

希望能帮助到你,

/ Angel

/ 天使