I'm trying to auto-deploy my webapps to tomcat using Maven plugin tomcat7-maven-plugin
. I took the following three steps:
- Added a new user with deployment rights to tomcat,
- Introduced the mentioned tomcat user to maven,
- Edited my project's pom.xml to use the plugin.
For the first step, I added the following lines to the file conf\tomcat-users.xml
in tomcat's installation directory:
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<user username="war-deployer" password="some-password"
roles="manager-gui,manager-script,manager-jmx" />
and then I restarted tomcat.
For the second step, I added the following to the <servers>
node of conf\settings.xml
file in MAVEN_HOME
directory:
<server>
<id>maven-tomcat-war-deployment-server</id>
<username>war-deployer</username>
<password>some-password</password>
</server>
And finally, to take to third step, I added the following lines to <plugins>
node of pom.xml
in my project to use tomcat7-maven-plugin
:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<url>http://localhost:8080/manager/text</url>
<path>/my-project-url-path</path>
</configuration>
</plugin>
I thought everything would go fine, but when typing the command mvn tomcat7:deploy
my webapp didn't get deployed, nothing was added to tomcat's webapps
directory, and the following response was sent back from tomcat to the command line:
[INFO] tomcatManager status code:401, ReasonPhrase:
[INFO] <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
[INFO] <html>
[INFO] <head>
[INFO] <title>401 Unauthorized</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>401 Unauthorized</h1>
[INFO] <p>
[INFO] You are not authorized to view this page. 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] <role rolename="manager-gui"/>
[INFO] <user username="tomcat" password="s3cret" roles="manager-gui"/>
[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" rel="noopener noreferrer">Manager App How-To</a>.
[INFO] </p>
[INFO] </body>
[INFO] </html>
Although no error was reported by maven, and I received a BUILD SUCCESS
at the end. I've been struggling with the problem for several hours, and searched the Web, but I couldn't find the solution to it. What's wrong with the process that I've followed? Please help me solve it. Thank you very much.
war-deployer
and its roles, I've changed none of the tomcat's default settings. – Hedayat Mahdipour Jan 1 '20 at 0:34