4

I have seen multiple locations where people besides myself have tried all solutions presented in this link, and after going through every page of results on Google, I have failed to find a result. I am trying to deploy a maven project to Tomcat, but I get the following printout:

[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

Both

mvn tomcat7:deploy

and

mvn tomcat7:redeploy

result in the same error.

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 (in both maven home and .m2 folder)

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

I am aware that my Tomcat version is 8, however, according to Borgy Manotoy, the Tomcat7 plugin will work for Tomcat 8.

Community
  • 1
  • 1
asdfghjkl
  • 41
  • 1
  • 3

2 Answers2

1

The same problem, solved by right credentials in Maven settings.xml. Yes, this error messages are misleading:

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

We use profiles in pom.xml, so:

<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>

and set maven "Tomcat plugin":

<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>

and finally settings.xml in Maven/conf:

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

Deploy:

   mvn tomcat7:deploy -Pstage_server
Radek
  • 393
  • 3
  • 15
  • I could upload the file from Postman so I knew the userid and password was right and the Tomcat server was setup correctly. I had the user and password in my settings.xml in the root of my project, but, it wasn't reading them and no error that it couldn't find my server. I moved the user and password directly into the POM.xml and it worked. I thought I had read I could put the settings.xml in the root of the project, but, I must be missing something. – J. Chaney Jan 10 '20 at 17:20
  • @J.Chaney I think you have to have the file settings.xml in Maven home directory in sub-directory "conf". If you have this file in Maven home/conf directory, will a deploy be successful? – Radek Jan 15 '20 at 13:54
0

I had the same error...

Using Java 7 from Windows host, targeting Tomcat 7 running in a local VM (VirtualBox). Accessing the Manager's app. from my browser worked perfectly fine (/html or /text).

It seems that the manager-gui & manager-script roles cannot be granted to the same user. So, I ended up having that deployer user with the manager-script role with which I was able to execute the Maven commands properly after:

<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>

References:

Community
  • 1
  • 1
Pierre Voisin
  • 661
  • 9
  • 11