Answers: <p>That's because you forgot to link the <code>&lt;configuration&gt;</code> for the plugin with the <code>&lt;server&gt;</code> definition in settings.xml., and the tomcat7 plugin is trying to deploy as un-authenticated because it has not credentials to try.</p>
  
  <p>Add <code>&lt;server&gt;maven-tomcat-war-deployment-server&lt;/server&gt;</code> in the configuration section of the plugin:    </p>
  
  <pre><code>&lt;configuration&gt;
      &lt;server&gt;maven-tomcat-war-deployment-server&lt;/server&gt;
      &lt;url&gt;http://localhost:8080/manager/text&lt;/url&gt;
      &lt;path&gt;/my-project-url-path&lt;/path&gt;
  &lt;/configuration&gt;
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2020-01-15T18:10:08.960Z
Answers: Thank you @GUDO. This solved the problem.
Answers: Hedayat Mahdipour
Answers: CC BY-SA 4.0
Answers: 2020-01-08T13:22:13.460Z
Answers: 2020-01-08T13:22:13.460Z
Answers: ᴳᵁᴵᴰᴼ
Body: <p>I'm trying to auto-deploy my webapps to tomcat using Maven plugin <code>tomcat7-maven-plugin</code>. I took the following three steps:</p>
  
  <ol>
  <li>Added a new user with deployment rights to tomcat,</li>
  <li>Introduced the mentioned tomcat user to maven,</li>
  <li>Edited my project's pom.xml to use the plugin.</li>
  </ol>
  
  <p>For the first step, I added the following lines to the file <code>conf\tomcat-users.xml</code> in tomcat's installation directory:</p>
  
  <pre><code>&lt;role rolename="manager-gui"/&gt;
  &lt;role rolename="manager-script"/&gt;
  &lt;role rolename="manager-jmx"/&gt;
  &lt;user username="war-deployer" password="some-password"
      roles="manager-gui,manager-script,manager-jmx" /&gt;
  </code></pre>
  
  <p>and then I restarted tomcat.</p>
  
  <p>For the second step, I added the following to the <code>&lt;servers&gt;</code> node of <code>conf\settings.xml</code> file in <code>MAVEN_HOME</code> directory:</p>
  
  <pre><code>&lt;server&gt;
      &lt;id&gt;maven-tomcat-war-deployment-server&lt;/id&gt;
      &lt;username&gt;war-deployer&lt;/username&gt;
      &lt;password&gt;some-password&lt;/password&gt;
  &lt;/server&gt;
  </code></pre>
  
  <p>And finally, to take to third step, I added the following lines to <code>&lt;plugins&gt;</code> node of <code>pom.xml</code> in my project to use <code>tomcat7-maven-plugin</code>:</p>
  
  <pre><code>&lt;plugin&gt;
      &lt;groupId&gt;org.apache.tomcat.maven&lt;/groupId&gt;
      &lt;artifactId&gt;tomcat7-maven-plugin&lt;/artifactId&gt;
      &lt;version&gt;2.0&lt;/version&gt;
      &lt;configuration&gt;
          &lt;url&gt;http://localhost:8080/manager/text&lt;/url&gt;
          &lt;path&gt;/my-project-url-path&lt;/path&gt;
      &lt;/configuration&gt;
  &lt;/plugin&gt;
  </code></pre>
  
  <p>I thought everything would go fine, but when typing the command <code>mvn tomcat7:deploy</code> my webapp didn't get deployed, nothing was added to tomcat's <code>webapps</code> directory, and the following response was sent back from tomcat to the command line:</p>
  
  <pre><code>[INFO] tomcatManager status code:401, ReasonPhrase:
  [INFO] &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
  [INFO] &lt;html&gt;
  [INFO]  &lt;head&gt;
  [INFO]   &lt;title&gt;401 Unauthorized&lt;/title&gt;
  [INFO]   &lt;style type="text/css"&gt;
  [INFO]     &lt;!--
  [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]     --&gt;
  [INFO]   &lt;/style&gt;
  [INFO]  &lt;/head&gt;
  [INFO]  &lt;body&gt;
  [INFO]    &lt;h1&gt;401 Unauthorized&lt;/h1&gt;
  [INFO]    &lt;p&gt;
  [INFO]     You are not authorized to view this page. If you have not changed
  [INFO]     any configuration files, please examine the file
  [INFO]     &lt;tt&gt;conf/tomcat-users.xml&lt;/tt&gt; in your installation. That
  [INFO]     file must contain the credentials to let you use this webapp.
  [INFO]    &lt;/p&gt;
  [INFO]    &lt;p&gt;
  [INFO]     For example, to add the &lt;tt&gt;manager-gui&lt;/tt&gt; role to a user named
  [INFO]     &lt;tt&gt;tomcat&lt;/tt&gt; with a password of &lt;tt&gt;s3cret&lt;/tt&gt;, add the following to the
  [INFO]     config file listed above.
  [INFO]    &lt;/p&gt;
  [INFO] &lt;pre&gt;
  [INFO] &amp;lt;role rolename="manager-gui"/&amp;gt;
  [INFO] &amp;lt;user username="tomcat" password="s3cret" roles="manager-gui"/&amp;gt;
  [INFO] &lt;/pre&gt;
  [INFO]    &lt;p&gt;
  [INFO]     Note that for Tomcat 7 onwards, the roles required to use the manager
  [INFO]     application were changed from the single &lt;tt&gt;manager&lt;/tt&gt; 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]    &lt;/p&gt;
  [INFO]     &lt;ul&gt;
  [INFO]       &lt;li&gt;&lt;tt&gt;manager-gui&lt;/tt&gt; - allows access to the HTML GUI and the status
  [INFO]           pages&lt;/li&gt;
  [INFO]       &lt;li&gt;&lt;tt&gt;manager-script&lt;/tt&gt; - allows access to the text interface and the
  [INFO]           status pages&lt;/li&gt;
  [INFO]       &lt;li&gt;&lt;tt&gt;manager-jmx&lt;/tt&gt; - allows access to the JMX proxy and the status
  [INFO]           pages&lt;/li&gt;
  [INFO]       &lt;li&gt;&lt;tt&gt;manager-status&lt;/tt&gt; - allows access to the status pages only&lt;/li&gt;
  [INFO]     &lt;/ul&gt;
  [INFO]    &lt;p&gt;
  [INFO]     The HTML interface is protected against CSRF but the text and JMX interfaces
  [INFO]     are not. To maintain the CSRF protection:
  [INFO]    &lt;/p&gt;
  [INFO]    &lt;ul&gt;
  [INFO]     &lt;li&gt;Users with the &lt;tt&gt;manager-gui&lt;/tt&gt; role should not be granted either
  [INFO]         the &lt;tt&gt;manager-script&lt;/tt&gt; or &lt;tt&gt;manager-jmx&lt;/tt&gt; roles.&lt;/li&gt;
  [INFO]     &lt;li&gt;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.&lt;/li&gt;
  [INFO]    &lt;/ul&gt;
  [INFO]    &lt;p&gt;
  [INFO]     For more information - please see the
  [INFO]     &lt;a href="/docs/manager-howto.html" rel="noopener noreferrer"&gt;Manager App How-To&lt;/a&gt;.
  [INFO]    &lt;/p&gt;
  [INFO]  &lt;/body&gt;
  [INFO] &lt;/html&gt;
  </code></pre>
  
  <p>Although no error was reported by maven, and I received a <code>BUILD SUCCESS</code> 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.</p>
  
Comments: CC BY-SA 4.0
Comments: 2019-12-31T22:02:26.237Z
Comments: Did you get a 401 with the default tomcat installation?
Comments: 030
Comments: CC BY-SA 4.0
Comments: 2020-01-01T00:34:45.163Z
Comments: @030 I don't know what you mean by default tomcat installation. But except for the settings related to adding the new user `war-deployer` and its roles, I've changed none of the tomcat's default settings.
Comments: Hedayat Mahdipour
Tags: <maven><tomcat>
Title: Unable to deploy webapp with `mvn tomcat7:deploy`: 401 Unauthorized
UserDisplayName: Hedayat Mahdipour
ThreadText: # Unable to deploy webapp with `mvn tomcat7:deploy`: 401 Unauthorized
  
  (Asked by: username_0 on 2019-12-31)
  
  I'm trying to auto-deploy my webapps to tomcat using Maven plugin `tomcat7-maven-plugin`. I took the following three steps:
  
  1. Added a new user with deployment rights to tomcat,
  2. Introduced the mentioned tomcat user to maven,
  3. 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] &lt;role rolename="manager-gui"/&gt;
  [INFO] &lt;user username="tomcat" password="s3cret" roles="manager-gui"/&gt;
  [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.
  
  **Tags:** maven, tomcat
  
  > **Comments:**
  > **username_1**: Did you get a 401 with the default tomcat installation?  
  > **username_0**: @username_1 I don't know what you mean by default tomcat installation. But except for the settings related to adding the new user `war-deployer` and its roles, I've changed none of the tomcat's default settings.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2020-01-08. Score: 1 | Accepted answer
  
  That's because you forgot to link the `<configuration>` for the plugin with the `<server>` definition in settings.xml., and the tomcat7 plugin is trying to deploy as un-authenticated because it has not credentials to try.
  
  Add `<server>maven-tomcat-war-deployment-server</server>` in the configuration section of the plugin:
  
  ```
  <configuration>
      <server>maven-tomcat-war-deployment-server</server>
      <url>http://localhost:8080/manager/text</url>
      <path>/my-project-url-path</path>
  </configuration>
  
  ```
  
  > **Comments:**
  > **username_0**: Thank you @GUDO. This solved the problem.  
  
  ---
  
  