Maven Tomcat7:部署“无法调用Tomcat管理器:连接被拒绝:连接”

时间:2015-03-07 10:16:48

标签: java maven tomcat maven-tomcat-plugin

我尝试使用Tomcat 7(版本3.2.1)在Maven上部署我的网络应用,但在标题中列出了异常。

我尝试过问题解答(tomcat:deploy: "Cannot invoke Tomcat manager: Connection refused"Tomcat deployement issue in a Maven project):

  1. 使用具有管理员脚本角色的tomcat用户(尊重编辑settings.xmlpom.xmltomcat-users.xml
  2. 在不指定tomcat用户的情况下进行部署。
  3. 使用diff maven命令,例如:clean install tomcat7:deployclean tomcat7:deploytomcat7:redeploytomcat7:redeploy-only
  4. 另外我应该提一下,如果我在没有maven的情况下在服务器上运行应用程序Project > Run As > Run on Server或使用maven tomcat7运行目标,即clean install tomcat7:run,那么一切正常。

    这是我在使用tomcat用户时编辑settings.xmlpom.xmltomcat-users.xml的方式。

    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>
    

    修改 我的Maven输出目标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
    

    ${CATALINA_HOME}/logs中也没有日志文件 - 我所拥有的是空文件夹。

    此外,我之前没有找到${project.dir}/target/tomcat文件夹。

    还应该检查this选项吗?

0 个答案:

没有答案