简体   繁体   English

tomcat-maven-plugin 403错误

[英]tomcat-maven-plugin 403 error

When I use mvn tomcat:deploy of tomcat-maven-plugin there is a 403 error: 当我使用tomcat-maven-plugin的mvn tomcat:deploy时,出现403错误:

Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.0:deploy (default-cli) on project my-webapp: Cannot invoke Tomcat manager: Server returned HTTP response code: 403 for URL: http://localhost:8080/manager/text/deploy?path=%2Fdms&war= 无法在项目my-webapp上执行目标org.codehaus.mojo:tomcat-maven-plugin:1.0:deploy(default-cli):无法调用Tomcat管理器:服务器返回的HTTP响应代码:403 for URL: http://localhost:8080/manager/text/deploy?path=%2Fdms&war=

I think it because of null war parameter. 我认为这是因为参数为空。 But why is it null??? 但是为什么它为空呢???

In pom.xml there is: 在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>

you should use /text: 您应该使用/ text:

http://localhost:8080/manager/text http:// localhost:8080 / manager / text

and also add to user role manager-script 并添加到用户角色管理器脚本中

You you're using tomcat 7, you should leave your plugin configuration in pom.xml like this: 您正在使用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>

I have tried with the version configuration, like above example, but it didn't work for me. 我已经尝试过使用版本配置,例如上面的示例,但是它对我不起作用。 In settings.xml shoud have the configuration of the server, matching with the value in the pom.xml 在settings.xml中应该具有服务器的配置,与pom.xml中的值匹配

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

So, mvn tomcat:deploy or mvn tomcat:redeploy (if you have deployed the app already), or mvn tomcat:run (with tomcat down) should work. 因此,应该使用mvn tomcat:deploy或mvn tomcat:redeploy(如果您已经部署了应用程序),或者mvn tomcat:run(将tomcat关闭)。

The /manager application is by default secured by username/password. 默认情况下, /manager应用程序由用户名/密码保护。 If you enter http://localhost:8080/manager you will be asked to provide security credentials as well. 如果输入http:// localhost:8080 / manager ,还将要求您提供安全凭证。 First create/enable user in Tomcat: after canceling or few unsuccessful attempts Tomcat will provide help on error screen. 首先在Tomcat中创建/启用用户:取消或尝试几次失败后,Tomcat将在错误屏幕上提供帮助。 Then use these credentials in tomcat-maven-plugin as explained here : 然后,在使用这些证书tomcat-maven-plugin作为解释在这里

Add a plugin configuration block to your pom.xml: 在您的pom.xml中添加一个插件配置块:

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

Add a corresponding server block to your settings.xml: 将相应的服务器块添加到您的settings.xml:

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

For Tomcat7, in tomcat-users.xml you need rolename manager-script also: 对于Tomcat7,在tomcat-users.xml中,您还需要角色名称管理器脚本

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

and in project's POM.xml 在项目的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>

and maven's settings.xml: 和Maven的settings.xml:

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

您只需要通过添加“ / html”来更改url,就可以像这样http:// localhost:8080 / manager / html and bingo起作用希望对您有所帮助

There are a few steps one must be sure that are accomplished. 必须确保完成一些步骤。 this can be a true black hole. 这可能是一个真正的黑洞。

If your are using tomcat-maven-plugin from org.codehaus.mojo, you must use this configuration: 如果您使用的是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>

Please ensure that you have 'server_name_on_settingsxml' server credentials defined on maven settings.xml. 请确保您在maven settings.xml上定义了“ server_name_on_settingsxml”服务器凭据。 Use mvn tomcat:deploy (you must use this 'tomcat' prefix), this is the only way that when deploying the above configurations are read. 使用mvn tomcat:deploy(必须使用此'tomcat'前缀),这是在部署上述配置时读取的唯一方法。

However if you are using tomcat7-maven-plugin from org.apache.tomcat.maven, you must use mvn tomcat7:deploy. 但是,如果您使用的是org.apache.tomcat.maven中的tomcat7-maven-plugin,则必须使用mvn tomcat7:deploy。 The 'tomcat7' prefix will read configuration from plugin: “ tomcat7”前缀将从插件读取配置:

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

I was using tomcat:deploy, and i had on the pom.xml the tomcat7-maven-plugin defined. 我正在使用tomcat:deploy,并且在pom.xml上定义了tomcat7-maven-plugin。 So, the maven deploy was never reading my configurations tag... 因此,Maven部署从未读取我的配置标签...

If you ensure you have usernames and passwords correctly define and you use the correct plugin when deploying, it will work. 如果您确保正确定义了用户名和密码,并且在部署时使用了正确的插件,那么它将起作用。

If you are using Tomcat 7: 如果您使用的是Tomcat 7:

  1. Change your configuration in pom.xml to use the Tomcat 7 version of the plugin 更改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> 

Notice the and values - they are DIFFERENT from the ones for Tomcat 6. 请注意和值-与Tomcat 6的和值不同。

  1. Don't forget to change the "tomcat:deploy" to "tomcat7:deploy" in your scripts, or External Tools Configurations launchers in Eclipse. 不要忘记在脚本或Eclipse中的“外部工具配置”启动器中将“ tomcat:deploy”更改为“ tomcat7:deploy”。
  2. Add a server configuration to your settings.xml, usually located under .m2 folder 将服务器配置添加到您的settings.xml中,通常位于.m2文件夹下
 <server> <id>TomcatServer</id> <username>some_user_name</username> <password>some_password</password> </server> 
  1. If you need additional options, like deploying a WAR file located in a non-standard folder, visit: Tomcat 7 Maven Plugin 如果您需要其他选项,例如部署位于非标准文件夹中的WAR文件,请访问: Tomcat 7 Maven插件

You can have a 403 error if you try to use the codehouse tomcat plugin version 1.1 to deploy on a Tomcat 7 server. 如果尝试使用Codehouse tomcat插件版本1.1在Tomcat 7服务器上进行部署,则可能会出现403错误。 Version 1.1 doesn't support Tomcat 7 yet. 1.1版尚不支持Tomcat 7。

If you are using Tomcat 7 you should use Cargo. 如果您使用的是Tomcat 7,则应使用Cargo。

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

http://localhost:8080/manager/text

This is also possible: 这也是可能的:

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

If you use Tomcat 7 you need to refer to the url http://localhost:8080/manager/html in the tomcat plugin. 如果使用Tomcat 7,则需要在tomcat插件中引用URL http:// localhost:8080 / manager / html

http://mojo.codehaus.org/tomcat-maven-plugin/examples/deployment-tomcat7.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>

If you are using version 7, there's a catch: the access to the /manager/text resource is not enabled by default. 如果使用的是版本7,则有一个陷阱:默认情况下,不启用对/ manager / text资源的访问。

You must create a user with the role mananger-script, as it says in the documentation 您必须创建一个角色mananger-script的用户,如文档中所述

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.

Hope it helps :) 希望能帮助到你 :)

I used to get the same error, you just have to make sure that tomcat-users.xml file contain the user (admin in my case) with roles as (manager, manager-gui, admin, manager-script). 我曾经遇到过同样的错误,您只需要确保tomcat-users.xml文件包含用户(在我的情况下为admin),其角色为(经理,manager-gui,admin,manager-script)。

I have tomcat 7, maven 3 on ubuntu. 我在Ubuntu上有tomcat 7,Maven 3。

May be you should check your configuration file in ~/.m2/settings.xml this file have to be with the follow struct : 可能是您应该在〜/ .m2 / settings.xml中检查您的配置文件,该文件必须具有以下struct:

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

After that you should to be sure that your server conf is correct for your project, instance of: 之后,您应确保您的服务器conf适用于您的项目,例如:

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

later run mvn tomcat:deploy. 稍后运行mvn tomcat:deploy。 Remember that also you could run tomcat:deploy -X for see the debbug. 请记住,您也可以运行tomcat:deploy -X来查看调试信息。

This solution is for "Apache" Tomcat7 plugin: As it is already mentioned before you need to add "/text" to the end of the url 此解决方案适用于“ Apache” Tomcat7插件:如前所述,您需要在URL末尾添加“ / text”

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

Configure you "settings.xml" which is located inside .m2 folder 配置位于.m2文件夹内的“ settings.xml”

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

Since you use Tomcat 7, the MOST important thing is that you should create a different user for "manager-script" role, as it is mentioned in the documentation! 由于您使用的是Tomcat 7,所以最重要的是,您应该为“ manager-script”角色创建一个不同的用户,如文档中所述!

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

You only have to add the manager-script and manager roles to your tomcat user in tomcat-users.xml in config folder. 您只需要在config文件夹中的tomcat-users.xml中向您的tomcat用户添加manager-script和manager角色。 In Tomcat 7 you have to specify different roles for different manager GUI access which in this case goes to text. 在Tomcat 7中,您必须为不同的管理器GUI访问指定不同的角色,在这种情况下,访问文本。 At the end for text interface you have to use a manager-script role. 在文本界面的最后,您必须使用经理脚本角色。

If you are facing a problem regarding user name and password please do not worry, there is a file in tomcat directory named tomcat-user.xml , go there and see the name and password attributes and use when the prompt ask for user name and password. 如果您遇到有关用户名和密码的问题,请不要担心,tomcat目录中有一个名为tomcat-user.xml ,请转到此处查看名称和密码属性,并在提示询问用户名和密码时使用。

If still you are unable to open apache home page do one thing, in the tomcat directory there is another file named server.xml go and change port 8080 to this 如果仍然无法打开apache主页做一件事,则在tomcat目录中还有另一个名为server.xml文件,将端口8080更改为此

If you are using Eclipse with the plugin m2eclipse and you still have this error after trying these solutions, it could be because this plugin has not the manager included. 如果您将Eclipse与插件m2eclipse一起使用,并且在尝试这些解决方案后仍然遇到此错误,则可能是因为此插件未包含管理器。 You should download Tomcat separately and configure Eclipse to use it (check this link: tomcat-maven-plugin: Server returned HTTP response code: 403 ) 您应该单独下载Tomcat并配置Eclipse以使用它(检查此链接: tomcat-maven-plugin:服务器返回的HTTP响应代码:403

Passing from tomcat6 to tomcat7 recap: 从tomcat6到tomcat7的回顾:

  1. Add roles in tomcat-user.xml 在tomcat-user.xml中添加角色
  2. Add /text or /html to your url 在您的网址中添加/ text或/ html
  3. Change plugin version 更改插件版本

     <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> 
  4. Change the option tomcat:deploy with tomcat7:deploy 使用tomcat7:deploy更改选项tomcat:deploy

I have spent over three days on Server returned HTTP response code: 400 while trying to deploy web application onto Tomcat Server 8.0 bundled with Netbeans. 在尝试将Web应用程序部署到与Netbeans捆绑在一起的Tomcat Server 8.0上时,我花了三天时间在Server返回的HTTP响应代码:400上。 When I used mvn tomcat7:deploy over command line, everything worked perfect, but no success through Netbeans IDE. 当我在命令行上使用mvn tomcat7:deploy ,一切工作正常,但通过Netbeans IDE却没有成功。 I have set tomcat maven plugin in POM.xml 我已经在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>

plus server record in .m2/conf/settings.xml for Maven, 加上Maven的.m2 / conf / settings.xml中的服务器记录,

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

even appropriate tomcat user in tomcat-users.xml 甚至tomcat-users.xml中合适的tomcat用户

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

but still without success. 但仍然没有成功。 The root cause was Proxy server used in our company and Netbeans settings. 根本原因是我们公司和Netbeans设置中使用的代理服务器。 In Netbeans, go to Tools -> Options and on General tab, use Manual Proxy Settings instead of System Proxy Settings (even if System Proxy Settings works). 在Netbeans中,转到“工具”->“选项”,然后在“常规”选项卡上,使用“手动代理设置”而不是“系统代理设置” (即使“系统代理设置”起作用)。 It helped me and now I am able to deploy web app on Tomcat 8 from Netbeans directly. 它帮助了我,现在我可以直接从Netbeans在Tomcat 8上部署Web应用程序。 You can also set No Proxy when you are using only localhost server. 当仅使用本地主机服务器时,也可以设置“无代理”。 Root cause for my trouble was bad proxy set in default web browser, which is the source for option System Proxy Settings. 我遇到麻烦的根本原因是在默认的Web浏览器中设置了错误的代理,这是选项“系统代理设置”的来源。

I also get the 403 error, but only when I connect via Apache 2. When I use port 8080 and deploy to tomcat directly it works. 我也收到403错误,但是仅当我通过Apache 2连接时。当我使用端口8080并直接部署到tomcat时,它可以工作。 So: try to add port 8080 to the URL 因此: 尝试将端口8080添加到URL

I am still trying to figure out why it does not work via Apache. 我仍在尝试弄清楚为什么它无法通过Apache工作。 I am using ProxyPass / ajp://localhost:8009/ and 我正在使用ProxyPass / ajp://localhost:8009/

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

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM