Umesh Awasthi
Umesh Awasthi

Reputation: 23587

Tomcat-maven-plugin 401 error

i am learning tomcat basics and while i tried to deploy my web-application on tomcat i am getting the following error

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

as per this it seems war file location is not being passed to the tomcat manager.i have the following entries in my tomcat-user.xml

tomcat-users>
<user name="admin" password="admin" roles="admin,manager" /><!--
  NOTE:  The sample user and role entries below are wrapped in a comment
  and thus are ignored when reading this file. Do not forget to remove
  <!.. ..> that surrounds them.
-->

<role rolename="manager"/>
  <role rolename="admin"/>
  <user username="admin" password="admin" roles="admin,manager"/>


</tomcat-users>

here are the details of the pom.xml

<build>
        <plugins>
        <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <packagingExcludes>WEB-INF/web.xml</packagingExcludes>
                </configuration>
            </plugin>
            <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>tomcat-maven-plugin</artifactId>
        <configuration>
                <warFile>${project.build.directory}/${project.build.finalName}.war</warFile>
                <url>http://localhost:8080/manager/html</url>
                <server>myserver</server>
                <path>/mkyWebApp</path>

        </configuration>
</plugin>

        </plugins>
    </build>

in my setting.xml there are the entries

<server>
      <id>Tomcat6.x</id>

      <username>admin</username>
      <password>admin</password>
    </server>

i am not sure what exactly is going wrong here.any help in this regard will be helpful.

Upvotes: 5

Views: 13857

Answers (5)

wikimix
wikimix

Reputation: 467

I Advise you to use this plugin :

 <groupId>org.codehaus.cargo</groupId>
  <artifactId>cargo-maven2-plugin</artifactId>
  <version>1.1.2</version>

It's very helpful with Tomcat7. I Have the same issue with mojo <groupId>org.codehaus.mojo</groupId> but now, using Cargo plugin, the deploy run smooth as silk.

Upvotes: 0

adam-singer
adam-singer

Reputation: 4837

When I was also running into this problem. My issue was using the older

 <groupId>org.codehaus.mojo</groupId>

instead of using

<groupId>org.apache.tomcat.maven</groupId>

My setup is as follows

~/.m2/settings.xml

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

pom.xml

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

tomcat/conf/tomcat-users.xml

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

Upvotes: 1

Mustafa SAHIN AYDIN
Mustafa SAHIN AYDIN

Reputation: 329

Change

<server>
  <id>Tomcat6.x</id>
  <username>admin</username>
  <password>admin</password>
</server>

to

<server>
  <id>myserver</id>
  <username>admin</username>
  <password>admin</password>
</server>

If you are using tomcat 7 use

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

If tomcat 6

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

start tomcat run tomcat7:deploy or tomcat6:deploy

Upvotes: 6

trybik
trybik

Reputation: 492

It's in the plugin configuration docs: the server/id tag in Maven settings must match the configuration/server value in your POM file, i.e. put <server>Tomcat6.x</server> in POM file.

There are some other minor issues with your tomcat-maven-plugin entry in the POM file:

  1. you are missing the <version>1.1</version> tag,
  2. the /html suffix in the Tomcat manager URL is unnecessary (cf. the default value for <url> tag).

Upvotes: 3

Tarlog
Tarlog

Reputation: 10154

You need to map the credentials from your settings.xml to the server configuration at your pom.xml.

In your case, this is done but setting the <id> element of your server, to match the server's host name from the pom.xml.

Since you are pointing localhost, the id must be also localhost. When you change the hostname, you must also update settings.xml.

Upvotes: 4

Related Questions