无法调用Tomcat管理器:软件导致连接中止

时间:2016-08-03 19:44:26

标签: maven tomcat

我已经看到多个地方,除了我自己以外的人都尝试了this link中提供的所有解决方案,在浏览了Google的每一页结果后,我都找不到结果。我正在尝试将maven项目部署到Tomcat,但我得到以下打印输出:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.178 s
[INFO] Finished at: 2016-08-03T15:01:17-04:00
[INFO] Final Memory: 15M/105M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy (default-cli) on project Project_2: Cannot invoke Tomcat manager: Software caused connection abort: socket write error -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[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

两个

mvn tomcat7:deploy

mvn tomcat7:redeploy

导致同样的错误。

的pom.xml

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <server>tomcat7</server>
        <path>/Project_2</path>
        <port>8085</port>
        <url>http://localhost:8085/manager/text</url>
        <update>true</update>
        <username>manager</username>
        <password>xxxx</password>
    </configuration>
</plugin>

Tomcat的users.xml中

<role rolename="manager-script"/>
<role rolename="manager-gui"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<role rolename="admin-gui"/>
<user username="admin1" password="xxxx" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-gui" />
<user username="manager" password="xxxx" roles="manager-script,admin-script" />

settings.xml(在maven home和.m2文件夹中)

<server>
  <id>tomcat7</id>
  <username>manager</username>
  <password>xxxx</password>
</server>

我知道我的Tomcat版本是8,但根据Borgy Manotoy,Tomcat7插件适用于Tomcat 8。

2 个答案:

答案 0 :(得分:0)

我有同样的错误......

使用Windows主机中的Java 7,以在本地VM(VirtualBox)中运行的Tomcat 7为目标。访问Manager的应用程序。从我的浏览器工作得很好(/html/text)。

似乎是manager-gui&amp; manager-script个角色无法授予同一用户。所以,我最终让deployer用户具有manager-script角色,在此之后我能够正确执行Maven命令:

<tomcat-users>
   <role rolename="admin-gui"/>
   <role rolename="manager-gui"/>
   <role rolename="manager-script"/>
   <user username="admin" password="..." roles="admin-gui,manager-gui"/>
   <user username="deployer" password="..." roles="manager-script"/>
</tomcat-users>

参考文献:

答案 1 :(得分:0)

相同的问题,可以通过 Maven settings.xml 中的正确凭据来解决。是的,此错误消息具有误导性:

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy (default-cli) on project projectXXX: Cannot invoke Tomcat manager
...
Caused by: org.apache.maven.plugin.MojoExecutionException: Cannot invoke Tomcat manager
...
Caused by: java.net.SocketException: Connection reset by peer: socket write error

我们在pom.xml中使用配置文件,所以:

<profile>
   <id>stage_server</id>
   <activation>
      <activeByDefault>true</activeByDefault>
   </activation>
   <properties>
      <tomcat-server>stage-server</tomcat-server>
      <tomcat-url>http://stage.server.com/manager/text</tomcat-url>
   </properties>
</profile>

并设置Maven“ Tomcat插件”:

<plugin>
   <groupId>org.apache.tomcat.maven</groupId>
   <artifactId>tomcat7-maven-plugin</artifactId>
   <version>2.2</version>
   <configuration>
      <url>${tomcat-url}</url>
      <server>${tomcat-server}</server>
      <update>true</update>
   </configuration>
</plugin>

最后是Maven / conf中的settings.xml:

<server>
  <id>stage-server</id>
  <username>admin</username>
  <password>xxxxx</password>
</server>

部署:

   mvn tomcat7:deploy -Pstage_server