0

I'm trying to deploy my web app on Tomcat 7 with Maven (version 3.2.1), but getting exception listed in the title.

I've tried following solutions from questions (tomcat:deploy: "Cannot invoke Tomcat manager: Connection refused", Tomcat deployement issue in a Maven project):

  1. Use tomcat user with manager-script role (respectfully edited settings.xml, pom.xml, tomcat-users.xml)
  2. Deploy without specifying tomcat user.
  3. Use diff maven commands e.g.: clean install tomcat7:deploy, clean tomcat7:deploy, tomcat7:redeploy, tomcat7:redeploy-only.

Also I should mention that if I'm running app on server without maven i.e. Project > Run As > Run on Server or using maven tomcat7-run goals i.e. clean install tomcat7:run then it all works as fine.

This is how I edit settings.xml, pom.xml, tomcat-users.xml when using tomcat user.

tomcat-users.xml:

<tomcat-users>
 <role rolename="manager-gui"/>
  <role rolename="manager-script"/>
  <role rolename="manager-jmx"/>
  <role rolename="manager-status"/>
  <role rolename="admin-gui"/>
  <role rolename="admin-script"/>
  <user username="user" password="pass" roles="manager-script"></user>
</tomcat-users>

settings.xml:

<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">
    <localRepository>${user.home}/.m2/repository</localRepository>
    <interactiveMode>true</interactiveMode>
    <usePluginRegistry>false</usePluginRegistry>
    <offline>false</offline>
    <servers>
      <server>
        <id>apache-tomcat-7</id>
        <username>user</username>
        <password>pass</password>
      </server>
    </servers>
</settings>

pom.xml:

<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">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.example.company</groupId>
    <artifactId>magazine</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>market Maven Webapp</name>
    <url>http://maven.apache.org</url>

    <build>
        <finalName>${project.artifactId}</finalName>
        <outputDirectory>${CATALINA_HOME}/webapps/${project.artifactId}/${project.artifactId}</outputDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <server>apache-tomcat-7</server>
                    <url>http://localhost:8080/manager/text</url>
                    <path>/${project.artifactId}</path>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
            </plugin>
        </plugins>
    </build>
    ...//dependencies
</project>

EDIT: My Maven output with goals clean install tomcat7:deploy -e

[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] >>> tomcat7-maven-plugin:2.2:deploy (default-cli) @ 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] 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] <<< tomcat7-maven-plugin:2.2:deploy (default-cli) @ magazine <<<
[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 -> [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

Also there is no log file in ${CATALINA_HOME}/logs - what I have is empty folder.

Besides there is no ${project.dir}/target/tomcat folder that I observed before.

Also should this option be checked ?

Community
  • 1
  • 1
marknorkin
  • 3,904
  • 10
  • 46
  • 82
  • Can you add the full output of maven and of `/logs/localhost_access_.log`? It might give hints what went wrong. – Alexander Mar 07 '15 at 22:05
  • @Alexander I edit my question. Please check it. – marknorkin Mar 08 '15 at 09:31
  • Are you sure a tomcat server runs on `localhost:8080` already when you execute `mvn`? (I do not think maven starts the tomcat; at least I cannot see this in the `pom.xml`.) Can you access http://localhost:8080/manager/html in the browser? – Clemens Klein-Robbenhaar Mar 08 '15 at 13:08
  • 1
    already posted the solution here: http://stackoverflow.com/a/33764689/2730735 Hope it helps. – aelkz Nov 17 '15 at 18:55

0 Answers0