maven - tomcat7-maven-plugin tomcatManager 状态码 :403, ReasonPhrase:Forbbiden

标签 maven tomcat7 maven-plugin

我正在尝试做 mvn clean package tomcat7:deploy但我总是收到此错误:tomcatManager status code:403, ReasonPhrase:Forbbiden
我的配置是下一个:

~/.m2/settings.xml

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

pom.xml
  <profiles>
    <profile>
        <id>tomcat-localhost</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <tomcat-server>localhost</tomcat-server>
            <tomcat-url>http://localhost:8080/manager/html</tomcat-url>
        </properties>
    </profile>
  </profiles>

  <build>
    <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.0</version>
        <configuration>
            <server>${tomcat-server}</server>
            <url>${tomcat-url}</url>
        </configuration>
      </plugin>
    </plugins>
  </build>

tomcat-users.xml
  <role rolename="manager-gui"/>  
  <user username="tomcat" password="s3cret" roles="manager-gui"/> 

我的错误是什么?因为我看不到。

完整消息错误:
[INFO] --- tomcat7-maven-plugin:2.0:deploy (default-cli) @ WebApp ---
[INFO] Deploying war to http://localhost:8080/Baskeitor  
Uploading: http://localhost:8080/manager/html/deploy?path=%2FWebApp
Uploaded: http://localhost:8080/manager/html/deploy?path=%2FWebApp (7985 KB at 50215.2 KB/sec)

[INFO] tomcatManager status code:403, ReasonPhrase:Prohibido
[INFO] <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
[INFO] <html>
[INFO]  <head>
[INFO]   <title>403 Access Denied</title>
[INFO]   <style type="text/css">
[INFO]     <!--
[INFO]     BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;font-size:12px;}
[INFO]     H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;}
[INFO]     PRE, TT {border: 1px dotted #525D76}
[INFO]     A {color : black;}A.name {color : black;}
[INFO]     -->
[INFO]   </style>
[INFO]  </head>
[INFO]  <body>
[INFO]    <h1>403 Access Denied</h1>
[INFO]    <p>
[INFO]     You are not authorized to view this page.
[INFO]    </p>
[INFO]    <p>
[INFO]     If you have already configured the Manager application to allow access and
[INFO]     you have used your browsers back button, used a saved book-mark or similar
[INFO]     then you may have triggered the cross-site request forgery (CSRF) protection
[INFO]     that has been enabled for the HTML interface of the Manager application. You
[INFO]     will need to reset this protection by returning to the
[INFO]     <a href="/manager/html">main Manager page</a>. Once you
[INFO]     return to this page, you will be able to continue using the Manager
[INFO]     appliction's HTML interface normally. If you continue to see this access
[INFO]     denied message, check that you have the necessary permissions to access this
[INFO]     application.
[INFO]    </p>
[INFO]    <p>
[INFO]     If you have not changed
[INFO]     any configuration files, please examine the file
[INFO]     <tt>conf/tomcat-users.xml</tt> in your installation. That
[INFO]     file must contain the credentials to let you use this webapp.
[INFO]    </p>
[INFO]    <p>
[INFO]     For example, to add the <tt>manager-gui</tt> role to a user named
[INFO]     <tt>tomcat</tt> with a password of <tt>s3cret</tt>, add the following to the
[INFO]     config file listed above.
[INFO]    </p>
[INFO] <pre>
[INFO] &lt;role rolename="manager-gui"/&gt;
[INFO] &lt;user username="tomcat" password="s3cret" roles="manager-gui"/&gt;
[INFO] </pre>
[INFO]    <p>
[INFO]     Note that for Tomcat 7 onwards, the roles required to use the manager
[INFO]     application were changed from the single <tt>manager</tt> role to the
[INFO]     following four roles. You will need to assign the role(s) required for
[INFO]     the functionality you wish to access.
[INFO]    </p>
[INFO]     <ul>
[INFO]       <li><tt>manager-gui</tt> - allows access to the HTML GUI and the status
[INFO]           pages</li>
[INFO]       <li><tt>manager-script</tt> - allows access to the text interface and the
[INFO]           status pages</li>
[INFO]       <li><tt>manager-jmx</tt> - allows access to the JMX proxy and the status
[INFO]           pages</li>
[INFO]       <li><tt>manager-status</tt> - allows access to the status pages only</li>
[INFO]     </ul>
[INFO]    <p>
[INFO]     The HTML interface is protected against CSRF but the text and JMX interfaces
[INFO]     are not. To maintain the CSRF protection:
[INFO]    </p>
[INFO]    <ul>
[INFO]     <li>Users with the <tt>manager-gui</tt> role should not be granted either
[INFO]         the <tt>manager-script</tt> or <tt>manager-jmx</tt> roles.</li>
[INFO]     <li>If the text or jmx interfaces are accessed through a browser (e.g. for
[INFO]         testing since these interfaces are intended for tools not humans) then
[INFO]         the browser must be closed afterwards to terminate the session.</li>
[INFO]    </ul>
[INFO]    <p>
[INFO]     For more information - please see the
[INFO]     <a href="/docs/manager-howto.html">Manager App HOW-TO</a>.
[INFO]    </p>
[INFO]  </body>
[INFO] </html>

我有 tomcat 7.0.32 并且我总是重新启动它我更改了一些关于用户的配置或任何需要再次加载的东西。

最佳答案

我有同样的问题。但我发现这个问题的以下解决方案:

pom.xml

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.0</version>
    <configuration>
      <url>http://localhost:8080/manager/text</url>
      <server>localhost</server>
      <path>/${project.build.finalName}</path>
    </configuration>
</plugin>

~/.m2/settings.xml
<servers>
<server>
   <id>localhost</id>
   <username>admin</username>
   <password>s3cret</password>
</server>

tomcat-users.xml
<role rolename="manager-script"/>
<user username="admin" password="s3cret" roles="manager-script"/>

更改 tomcat-users.xml 后不要忘记重新启动服务器。也不要将 manager-gui 角色与 manager-script 分配给同一用户。

关于maven - tomcat7-maven-plugin tomcatManager 状态码 :403, ReasonPhrase:Forbbiden,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13336816/

相关文章:

maven - 如何使用 Maven 创建 .war 文件?

java - IDEA编译错误 Unknown version '8' ,不会给编译器任何版本设置

java - STS 3.6 RELEASE 错误运行服务器

deployment - Tomcat 7 跳过从 webapps 加载特定文件夹

java - 如何在 mac 安装程序的 java 中更改安装程序的 java 默认图标

html - 使用 Maven 插件从 XSD 生成 HTML 文档

java - 让 JRebel 与 'mvn tomcat:run' 一起工作

java - Maven:如何更新 html 文件以使用新的缩小和连接的 JS 和 CSS 文件?

java - Maven parent hierarchy + dependencyManagement 不传递?

java - 连接太多,AWS EC2 上的 tomcat7