Error Tomcat-maven-plugin 401

I am learning the basics of tomcat, and although I tried to deploy my web application to tomcat, I get 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] 

according to this, it seems that the location of the war file is not being transferred to tomcat manager. In my tomcat-user.xml

There are the following entries:
 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 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> 

there are entries in my settings.xml

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

Iā€™m not sure what exactly is happening wrong here. Help in this regard will be helpful.

+4
source share
5 answers

You need to match the credentials from your settings.xml with the server configuration on your pom.xml.

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

Since you specify localhost , the identifier must also be localhost . When changing the host name, you must also update settings.xml.

+4
source

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

+5
source

It is located in the plugins configuration plugins : the server/id tag in the Maven settings should correspond to the configuration/server value in your POM file, i.e. put <server>Tomcat6.x</server> in the POM file.

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

  • you are missing the <version>1.1</version> ,
  • The suffix /html in the Tomcat manager URL is not needed (see the default value for the <url> ).
+2
source

When I also came across this problem. My problem was using an older

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

instead

 <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> 
+1
source

I advise you to use this plugin:

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

This is very useful with Tomcat7. I have the same problem with mojo <groupId>org.codehaus.mojo</groupId> but now, using the Cargo plugin, the deployment runs smoothly like silk.

0
source

All Articles