使用tomcat7-maven-plugin进行Tomcat部署失败,并显示错误“无法调用Tomcat管理器:通过对等方重置连接:套接字写入错误”

时间:2017-11-18 07:02:07

标签: java maven tomcat plugins tomcat8.5

我正在尝试使用Tomcat7-Maven-Plugin为我的战争设置自动部署。但是,它无法部署文件。从控制台消息看,它看起来像是开始部署,但在转移2 MB之后中断。所有重试都会发生同样的情况,最终失败。

$ mvn tomcat7:redeploy
    .
    .
    .  
[INFO] Deploying war to http://localhost:8080/policy-service
Uploading: http://localhost:8080/manager/text/deploy?path=%2Fpolicy-service&update=true
2244/52241 KB
[INFO] I/O exception (java.net.SocketException) caught when processing request: Connection reset by peer: socket write error
[INFO] Retrying request
Uploading: http://localhost:8080/manager/text/deploy?path=%2Fpolicy-service&update=true
2242/52241 KB
[INFO] I/O exception (java.net.SocketException) caught when processing request: Connection reset by peer: socket write error
[INFO] Retrying request
Uploading: http://localhost:8080/manager/text/deploy?path=%2Fpolicy-service&update=true
2242/52241 KB
[INFO] I/O exception (java.net.SocketException) caught when processing request: Connection reset by peer: socket write error
[INFO] Retrying request
Uploading: http://localhost:8080/manager/text/deploy?path=%2Fpolicy-service&update=true
2242/52241 KB
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

我尝试了所有可能的解决方案,但我没有运气:

  1. 将/ manager / text中的POM配置URL更改为/ manager / html。
  2. 未将manager-script或manager-jmx角色分配给tomcat-users.xml中具有manager-gui角色的同一用户。
  3. 在server.xml中将连接器超时设置为20秒到60秒
  4. 将max-file-size从默认的50 MB更改为80 MB。 (因为我的war文件大小是55 MB。)
  5. 其他一些细节如下:

    • Pom.xml片段:

      <plugins>            
          <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-compiler-plugin</artifactId>
              <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>  
                    <url>http://localhost:8080/manager/text</url>  
                    <server>TomcatServer</server>    
                    <username>xxx</username>  
                    <password>xxx</password>
                    <path>/policy-service</path>   
              </configuration>
          </plugin>
      </plugins>
      
    • Maven verion:3.5.2

    • Tomcat版本:8.5.32

    • JDK版本:1.8.0_144

    • 将war部署到tomcat时获得的异常的完整堆栈跟踪

        [ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:redeploy (default-cli) on project policy-service: Cannot invoke Tomcat manager: Connection reset by peer: socket write error -> [Help 1]
        org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:redeploy (default-cli) on project policy-service: Cannot invoke Tomcat manager
            at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213)
            at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
            at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
            at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
            at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
            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:309)
            at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:194)
            at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:107)
            at org.apache.maven.cli.MavenCli.execute (MavenCli.java:955)
            at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
            at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
            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:498)
            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:134)
            at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208)
            at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
            at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
            at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
            at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
            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:309)
            at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:194)
            at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:107)
            at org.apache.maven.cli.MavenCli.execute (MavenCli.java:955)
            at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
            at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
            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:498)
            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: java.net.SocketException: Connection reset by peer: socket write error
            at java.net.SocketOutputStream.socketWrite0 (Native Method)
            at java.net.SocketOutputStream.socketWrite (SocketOutputStream.java:111)
            at java.net.SocketOutputStream.write (SocketOutputStream.java:155)
            at org.apache.http.impl.io.AbstractSessionOutputBuffer.write (AbstractSessionOutputBuffer.java:181)
            at org.apache.http.impl.conn.LoggingSessionOutputBuffer.write (LoggingSessionOutputBuffer.java:73)
            at org.apache.http.impl.io.ContentLengthOutputStream.write (ContentLengthOutputStream.java:115)
            at org.apache.tomcat.maven.common.deployer.TomcatManager$RequestEntityImplementation.writeTo (TomcatManager.java:880)
            at org.apache.http.entity.HttpEntityWrapper.writeTo (HttpEntityWrapper.java:89)
            at org.apache.http.impl.client.EntityEnclosingRequestWrapper$EntityWrapper.writeTo (EntityEnclosingRequestWrapper.java:108)
            at org.apache.http.impl.entity.EntitySerializer.serialize (EntitySerializer.java:117)
            at org.apache.http.impl.AbstractHttpClientConnection.sendRequestEntity (AbstractHttpClientConnection.java:265)
            at org.apache.http.impl.conn.ManagedClientConnectionImpl.sendRequestEntity (ManagedClientConnectionImpl.java:203)
            at org.apache.http.protocol.HttpRequestExecutor.doSendRequest (HttpRequestExecutor.java:236)
            at org.apache.http.protocol.HttpRequestExecutor.execute (HttpRequestExecutor.java:121)
            at org.apache.http.impl.client.DefaultRequestDirector.tryExecute (DefaultRequestDirector.java:682)
            at org.apache.http.impl.client.DefaultRequestDirector.execute (DefaultRequestDirector.java:486)
            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)
            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)
            at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
            at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
            at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
            at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
            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:309)
            at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:194)
            at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:107)
            at org.apache.maven.cli.MavenCli.execute (MavenCli.java:955)
            at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
            at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
            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:498)
            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)
      

1 个答案:

答案 0 :(得分:1)

我解决了这个问题。问题是我使用的管理员用户可以访问manager-gui和manager-status。对于部署,它需要管理员脚本角色访问权限。我创建了具有此角色的新用户,并在我的pom.xml中使用了该用户并且它有效。

以下是我在tomcat-users.xml中添加的条目:

<user username="script" password="xxxx" roles="manager-script,manager-jmx"/>