title: Maven Tomcat7:deploy "Cannot invoke Tomcat manager: Connection refused: connect"
body: <p>I'm trying to deploy my web app on <code>Tomcat 7</code> with <code>Maven</code> (version 3.2.1), but getting exception listed in the title.</p>
  
  <p>I've tried following solutions from questions (<a href="https://stackoverflow.com/questions/15410914/tomcatdeploy-cannot-invoke-tomcat-manager-connection-refused">tomcat:deploy: &quot;Cannot invoke Tomcat manager: Connection refused&quot;</a>, <a href="https://stackoverflow.com/questions/14602744/tomcat-deployement-issue-in-a-maven-project">Tomcat deployement issue in a Maven project</a>):</p>
  
  <ol>
  <li>Use tomcat user with manager-script role (respectfully edited <code>settings.xml</code>, <code>pom.xml</code>, <code>tomcat-users.xml</code>)</li>
  <li>Deploy without specifying tomcat user.</li>
  <li>Use diff maven commands e.g.: <code>clean install tomcat7:deploy</code>, <code>clean tomcat7:deploy</code>, <code>tomcat7:redeploy</code>, <code>tomcat7:redeploy-only</code>.</li>
  </ol>
  
  <p>Also I should mention that if I'm running app on server without maven i.e. <code>Project &gt; Run As &gt; Run on Server</code> or using maven tomcat7-run goals i.e. <code>clean install tomcat7:run</code> then it all works as fine.</p>
  
  <p>This is how I edit <code>settings.xml</code>, <code>pom.xml</code>, <code>tomcat-users.xml</code> when using tomcat user.</p>
  
  <p><code>tomcat-users.xml</code>:</p>
  
  <pre><code>&lt;tomcat-users&gt;
   &lt;role rolename="manager-gui"/&gt;
    &lt;role rolename="manager-script"/&gt;
    &lt;role rolename="manager-jmx"/&gt;
    &lt;role rolename="manager-status"/&gt;
    &lt;role rolename="admin-gui"/&gt;
    &lt;role rolename="admin-script"/&gt;
    &lt;user username="user" password="pass" roles="manager-script"&gt;&lt;/user&gt;
  &lt;/tomcat-users&gt;
  </code></pre>
  
  <p><code>settings.xml:</code></p>
  
  <pre><code>&lt;settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                        http://maven.apache.org/xsd/settings-1.0.0.xsd"&gt;
      &lt;localRepository&gt;${user.home}/.m2/repository&lt;/localRepository&gt;
      &lt;interactiveMode&gt;true&lt;/interactiveMode&gt;
      &lt;usePluginRegistry&gt;false&lt;/usePluginRegistry&gt;
      &lt;offline&gt;false&lt;/offline&gt;
      &lt;servers&gt;
        &lt;server&gt;
          &lt;id&gt;apache-tomcat-7&lt;/id&gt;
          &lt;username&gt;user&lt;/username&gt;
          &lt;password&gt;pass&lt;/password&gt;
        &lt;/server&gt;
      &lt;/servers&gt;
  &lt;/settings&gt;
  </code></pre>
  
  <p><code>pom.xml:</code></p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;org.example.company&lt;/groupId&gt;
      &lt;artifactId&gt;magazine&lt;/artifactId&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;market Maven Webapp&lt;/name&gt;
      &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  
      &lt;build&gt;
          &lt;finalName&gt;${project.artifactId}&lt;/finalName&gt;
          &lt;outputDirectory&gt;${CATALINA_HOME}/webapps/${project.artifactId}/${project.artifactId}&lt;/outputDirectory&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;3.1&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.8&lt;/source&gt;
                      &lt;target&gt;1.8&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &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;apache-tomcat-7&lt;/server&gt;
                      &lt;url&gt;http://localhost:8080/manager/text&lt;/url&gt;
                      &lt;path&gt;/${project.artifactId}&lt;/path&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.4&lt;/version&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
      ...//dependencies
  &lt;/project&gt;
  </code></pre>
  
  <p><strong>EDIT:</strong>
  My Maven output with goals <code>clean install tomcat7:deploy -e</code></p>
  
  <pre><code>[INFO] Error stacktraces are turned on.
  [INFO] Scanning for projects...
  [INFO] 
  [INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
  [INFO]                                                                         
  [INFO] ------------------------------------------------------------------------
  [INFO] Building market Maven Webapp 0.0.1-SNAPSHOT
  [INFO] ------------------------------------------------------------------------
  [INFO] 
  [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ magazine ---
  [INFO] Deleting D:\git\magazine\target
  [INFO] Deleting D:\EclipseWorkspace\apache-tomcat-7.0.59\webapps\magazine\magazine
  [INFO] 
  [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ magazine ---
  [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
  [INFO] Copying 4 resources
  [INFO] 
  [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ magazine ---
  [INFO] Changes detected - recompiling the module!
  [WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
  [INFO] Compiling 19 source files to D:\EclipseWorkspace\apache-tomcat-7.0.59\webapps\magazine\magazine
  [INFO] 
  [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ magazine ---
  [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
  [INFO] skip non existing resourceDirectory D:\git\magazine\src\test\resources
  [INFO] 
  [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ magazine ---
  [INFO] No sources to compile
  [INFO] 
  [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ magazine ---
  [INFO] No tests to run.
  [INFO] 
  [INFO] --- maven-war-plugin:2.4:war (default-war) @ magazine ---
  [INFO] Packaging webapp
  [INFO] Assembling webapp [magazine] in [D:\git\magazine\target\magazine]
  [INFO] Processing war project
  [INFO] Copying webapp resources [D:\git\magazine\src\main\webapp]
  [INFO] Webapp assembled in [376 msecs]
  [INFO] Building war: D:\git\magazine\target\magazine.war
  [INFO] 
  [INFO] --- maven-install-plugin:2.4:install (default-install) @ magazine ---
  [INFO] Installing D:\git\magazine\target\magazine.war to C:\Users\Mark\.m2\repository\ua\khpi\norkin\magazine\0.0.1-SNAPSHOT\magazine-0.0.1-SNAPSHOT.war
  [INFO] Installing D:\git\magazine\pom.xml to C:\Users\Mark\.m2\repository\ua\khpi\norkin\magazine\0.0.1-SNAPSHOT\magazine-0.0.1-SNAPSHOT.pom
  [INFO] 
  [INFO] &gt;&gt;&gt; tomcat7-maven-plugin:2.2:deploy (default-cli) @ magazine &gt;&gt;&gt;
  [INFO] 
  [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ magazine ---
  [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
  [INFO] Copying 4 resources
  [INFO] 
  [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ magazine ---
  [INFO] Nothing to compile - all classes are up to date
  [INFO] 
  [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ magazine ---
  [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
  [INFO] skip non existing resourceDirectory D:\git\magazine\src\test\resources
  [INFO] 
  [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ magazine ---
  [INFO] No sources to compile
  [INFO] 
  [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ magazine ---
  [INFO] No tests to run.
  [INFO] Skipping execution of surefire because it has already been run for this configuration
  [INFO] 
  [INFO] --- maven-war-plugin:2.4:war (default-war) @ magazine ---
  [INFO] Packaging webapp
  [INFO] Assembling webapp [magazine] in [D:\git\magazine\target\magazine]
  [INFO] Processing war project
  [INFO] Copying webapp resources [D:\git\magazine\src\main\webapp]
  [INFO] Webapp assembled in [221 msecs]
  [INFO] Building war: D:\git\magazine\target\magazine.war
  [INFO] 
  [INFO] &lt;&lt;&lt; tomcat7-maven-plugin:2.2:deploy (default-cli) @ magazine &lt;&lt;&lt;
  [INFO] 
  [INFO] --- tomcat7-maven-plugin:2.2:deploy (default-cli) @ magazine ---
  [INFO] Deploying war to http://localhost:8080/magazine  
  [INFO] ------------------------------------------------------------------------
  [INFO] BUILD FAILURE
  [INFO] ------------------------------------------------------------------------
  [INFO] Total time: 10.622 s
  [INFO] Finished at: 2015-03-08T11:09:46+02:00
  [INFO] Final Memory: 25M/221M
  [INFO] ------------------------------------------------------------------------
  [ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy (default-cli) on project magazine: Cannot invoke Tomcat manager: Connection refused: connect -&gt; [Help 1]
  org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy (default-cli) on project magazine: 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:108)
      at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76)
      at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
      at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:116)
      at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:361)
      at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
      at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
      at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
      at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
      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:483)
      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: Cannot invoke Tomcat manager
      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:133)
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
      ... 19 more
  Caused by: java.net.ConnectException: Connection refused: connect
      at java.net.DualStackPlainSocketImpl.connect0(Native Method)
      at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
      at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
      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)
      ... 22 more
  [ERROR] 
  [ERROR] Re-run Maven using the -X switch to enable full debug logging.
  [ERROR] 
  [ERROR] For more information about the errors and possible solutions, please read the following articles:
  [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
  </code></pre>
  
  <p>Also there is no log file in <code>${CATALINA_HOME}/logs</code> - what I have is empty folder.</p>
  
  <p>Besides there is no <code>${project.dir}/target/tomcat</code> folder that I observed before.</p>
  
  <p>Also should <a href="https://stackoverflow.com/questions/14659891/m2e-wtp-error-path-target-m2e-wtp-web-resources-meta-inf-manifest-mf-no-such">this</a> option be checked ?</p>