开发者

tomcat-maven-plugin 403 error

When I use mvn tomcat:deploy of tomcat-maven-plugin there is a 403 error:

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=

I think it because of null war parameter. But why is it null???

In pom.xml there is:

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

  <configuration>
    <warFile>target\my-webapp.war</warFile&g开发者_运维百科t;
    <server>myserver</server>
    <url>http://localhost:8080/manager/text</url>
    <path>/dms</path>
  </configuration>
</plugin>


you should use /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:

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


The /manager application is by default secured by username/password. If you enter http://localhost:8080/manager you will be asked to provide security credentials as well. First create/enable user in Tomcat: after canceling or few unsuccessful attempts Tomcat will provide help on error screen. Then use these credentials in tomcat-maven-plugin as explained here:

Add a plugin configuration block to your 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:

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


you just have to change the url by adding the "/html" so it will be like this http://localhost:8080/manager/html and bingo it works Hope that help


For Tomcat7, in tomcat-users.xml you need rolename manager-script also:

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

and in project's 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:

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


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:

<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. Use mvn tomcat:deploy (you must use this 'tomcat' prefix), this is the only way that when deploying the above configurations are read.

However if you are using tomcat7-maven-plugin from org.apache.tomcat.maven, you must use mvn tomcat7:deploy. The 'tomcat7' prefix will read configuration from plugin:

        <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. So, the maven deploy was never reading my configurations tag...

If you ensure you have usernames and passwords correctly define and you use the correct plugin when deploying, it will work.


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. Version 1.1 doesn't support Tomcat 7 yet.

If you are using Tomcat 7 you should use Cargo.


If you are using Tomcat 7:

  1. Change your configuration in pom.xml to use the Tomcat 7 version of the plugin

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

  1. Don't forget to change the "tomcat:deploy" to "tomcat7:deploy" in your scripts, or External Tools Configurations launchers in Eclipse.
  2. Add a server configuration to your settings.xml, usually located under .m2 folder
<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


I discovered that I had to use the following string instead of "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.

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.

You must create a user with the role mananger-script, as it says in the 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.

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

I have tomcat 7, maven 3 on ubuntu.


You only have to add the manager-script and manager roles to your tomcat user in tomcat-users.xml in config folder. In Tomcat 7 you have to specify different roles for different manager GUI access which in this case goes to text. At the end for text interface you have to use a manager-script role.


May be you should check your configuration file in ~/.m2/settings.xml this file have to be with the follow 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:

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

later run mvn tomcat:deploy. Remember that also you could run tomcat:deploy -X for see the debbug.


This solution is for "Apache" Tomcat7 plugin: As it is already mentioned before you need to add "/text" to the end of the 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>

Configure you "settings.xml" which is located inside .m2 folder

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

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


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.

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


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. You should download Tomcat separately and configure Eclipse to use it (check this link: tomcat-maven-plugin: Server returned HTTP response code: 403)


Passing from tomcat6 to tomcat7 recap:

  1. Add roles in tomcat-user.xml
  2. Add /text or /html to your url
  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


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. When I used mvn tomcat7:deploy over command line, everything worked perfect, but no success through Netbeans IDE. I have set tomcat maven plugin in POM.xml

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

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

even appropriate tomcat user in tomcat-users.xml

<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. 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). It helped me and now I am able to deploy web app on Tomcat 8 from Netbeans directly. 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.


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. So: try to add port 8080 to the URL

I am still trying to figure out why it does not work via Apache. I am using ProxyPass / ajp://localhost:8009/ and

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜