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

CC BY-SA 4.0
2020-01-15T18:10:08.960Z
Thank you @GUDO. This solved the problem.
Hedayat Mahdipour
CC BY-SA 4.0
2020-01-08T13:22:13.460Z
2020-01-08T13:22:13.460Z
ᴳᵁᴵᴰᴼ
<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>

CC BY-SA 4.0
2019-12-31T22:02:26.237Z
Did you get a 401 with the default tomcat installation?
030
CC BY-SA 4.0
2020-01-01T00:34:45.163Z
@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.
Hedayat Mahdipour
<maven><tomcat>
Unable to deploy webapp with `mvn tomcat7:deploy`: 401 Unauthorized
Hedayat Mahdipour
# 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:

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:





and then I restarted tomcat.
For the second step, I added the following to the  node of conf\settings.xml file in MAVEN_HOME directory:

    maven-tomcat-war-deployment-server
    war-deployer
    some-password


And finally, to take to third step, I added the following lines to  node of pom.xml in my project to use tomcat7-maven-plugin:

    org.apache.tomcat.maven
    tomcat7-maven-plugin
    2.0
    
        http://localhost:8080/manager/text
        /my-project-url-path
    


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] 
[INFO] 
[INFO]  
[INFO]   401 Unauthorized
[INFO]   
[INFO]  
[INFO]  
[INFO]    401 Unauthorized
[INFO]    
[INFO]     You are not authorized to view this page. If you have not changed
[INFO]     any configuration files, please examine the file
[INFO]     conf/tomcat-users.xml in your installation. That
[INFO]     file must contain the credentials to let you use this webapp.
[INFO]    
[INFO]    
[INFO]     For example, to add the manager-gui role to a user named
[INFO]     tomcat with a password of s3cret, add the following to the
[INFO]     config file listed above.
[INFO]    
[INFO] 
[INFO] <role rolename="manager-gui"/>
[INFO] <user username="tomcat" password="s3cret" roles="manager-gui"/>
[INFO] 
[INFO]    
[INFO]     Note that for Tomcat 7 onwards, the roles required to use the manager
[INFO]     application were changed from the single manager 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]    
[INFO]     
[INFO]       manager-gui - allows access to the HTML GUI and the status
[INFO]           pages
[INFO]       manager-script - allows access to the text interface and the
[INFO]           status pages
[INFO]       manager-jmx - allows access to the JMX proxy and the status
[INFO]           pages
[INFO]       manager-status - allows access to the status pages only
[INFO]     
[INFO]    
[INFO]     The HTML interface is protected against CSRF but the text and JMX interfaces
[INFO]     are not. To maintain the CSRF protection:
[INFO]    
[INFO]    
[INFO]     Users with the manager-gui role should not be granted either
[INFO]         the manager-script or manager-jmx roles.
[INFO]     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.
[INFO]    
[INFO]    
[INFO]     For more information - please see the
[INFO]     Manager App How-To.
[INFO]    
[INFO]  
[INFO] 

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  for the plugin with the  definition in settings.xml., and the tomcat7 plugin is trying to deploy as un-authenticated because it has not credentials to try.
Add maven-tomcat-war-deployment-server in the configuration section of the plugin:    

    maven-tomcat-war-deployment-server
    http://localhost:8080/manager/text
    /my-project-url-path

> **Comments:**
> **username_0**: Thank you @GUDO. This solved the problem.  

---

