title: Maven tomcat plugin - cannot invoke Tomcat manager
body: <p>I'm trying to deploy my web app on Tomcat 7 with Maven (version 3.3.3), but I'm getting the exception listed in the title.</p>
  
  <p>I've tried many solutions but no one works for me.</p>
  
  <p>I had:</p>
  
  <ol>
  <li><p>Edited <code>tomcat-users.xml</code> ($CATALINA_HOME/conf/tomcat-user.xml):</p>
  
  <pre><code>&lt;tomcat-users&gt;
      &lt;role rolename="manager-gui"/&gt;
      &lt;role rolename="manager-script"/&gt;
      &lt;user username="user" password="pass" roles="manager-script"/&gt;
      &lt;user username="user2" password="pass2" roles="manager-gui"/&gt;
  &lt;/tomcat-users&gt;
  </code></pre></li>
  <li><p>Edited <code>settings.xml</code> ($USER_HOME/.m2/settings.xml):</p>
  
  <pre><code>&lt;servers&gt;
      &lt;server&gt;
           &lt;id&gt;RemoteServer&lt;/id&gt;
           &lt;username&gt;user&lt;/username&gt;
           &lt;password&gt;pass&lt;/password&gt;
      &lt;/server&gt;
  &lt;/servers&gt;
  </code></pre></li>
  <li><p>Configured <code>pom.xml</code> ($MY_PROJECT/pom.xml):</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.2&lt;/version&gt; 
       &lt;configuration&gt;
           &lt;server&gt;RemoteServer&lt;/server&gt;
           &lt;url&gt;http://my.public.ip.address:8080/manager/text&lt;/url&gt;
           &lt;username&gt;user&lt;/username&gt;
           &lt;password&gt;pass&lt;/password&gt;
       &lt;/configuration&gt;   
   &lt;/plugin&gt;
  </code></pre></li>
  <li><p>Edited <code>context.xml</code> ($CATALINA_HOME/webapps/manager/META-INF/context.xml)</p>
  
  <pre><code> &lt;Context antiResourceLocking="false" privileged="true" &gt;
   &lt;!--
        &lt;Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /&gt;
   --&gt;
   &lt;Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/&gt;
   &lt;/Context&gt;
  </code></pre></li>
  </ol>
  
  <p>Additional notes:</p>
  
  <ul>
  <li><p>I tried to deploy both to 8.0.45 and 8.5.16 (for the latter server, the configuration in context.xml was fundamental)</p></li>
  <li><p>I can access the manager GUI with no problem</p></li>
  <li><p>The username/password in the pom "should" be an overkill, but I read around that could help, in any case I tried also without those attributes</p></li>
  <li><p>If I test the manager/text (for example manager/text/deploy from the browser) I get a response (FAIL - Invalid parameters supplied for command [/deploy] and that's fine)</p></li>
  </ul>
  
  <p>The error I get is:</p>
  
  <p>[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy (default-cli) on project ShareRideServer: <strong>Cannot invoke Tomcat manager: Connection refused: connect -> [Help 1]</strong>
  org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy (default-cli) on project ShareRideServer: Cannot invoke Tomcat manager
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
      at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
      at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
      at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
      at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
      at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
      at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
      at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
      at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
      at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
      at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
      at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
      at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
      at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
  Caused by: org.apache.maven.plugin.MojoExecutionException: <strong>Cannot invoke Tomcat manager</strong>
      at org.apache.tomcat.maven.plugin.tomcat7.AbstractCatalinaMojo.execute(AbstractCatalinaMojo.java:141)
      at org.apache.tomcat.maven.plugin.tomcat7.AbstractWarCatalinaMojo.execute(AbstractWarCatalinaMojo.java:68)
      at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
      ... 20 more
  <strong>Caused by: java.net.ConnectException: Connection refused: connect</strong>
      at java.net.DualStackPlainSocketImpl.connect0(Native Method)
      at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
      at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
      at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
      at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
      at java.net.Socket.connect(Socket.java:589)
      at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:117)
      at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:178)
      at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:304)
      at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:610)
      at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:445)
      at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:863)
      at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
      at org.apache.tomcat.maven.common.deployer.TomcatManager.invoke(TomcatManager.java:742)
      at org.apache.tomcat.maven.common.deployer.TomcatManager.deployImpl(TomcatManager.java:705)
      at org.apache.tomcat.maven.common.deployer.TomcatManager.deploy(TomcatManager.java:388)
      at org.apache.tomcat.maven.plugin.tomcat7.deploy.AbstractDeployWarMojo.deployWar(AbstractDeployWarMojo.java:85)
      at org.apache.tomcat.maven.plugin.tomcat7.deploy.AbstractDeployMojo.invokeManager(AbstractDeployMojo.java:82)
      at org.apache.tomcat.maven.plugin.tomcat7.AbstractCatalinaMojo.execute(AbstractCatalinaMojo.java:132)
      ... 23 more</p>