📜 ⬆️ ⬇️

Updating a web application on a remote server after building with Maven via SSH

Problem


After building the project using the Build server or on a local machine, you need to upload the resulting application to the test server.

Decision


Add a special profile to pom.xml, in which using a plugin
<profiles> <profile> <id>deployApp</id> <activation> <activeByDefault>false</activeByDefault> </activation> <build> <plugins> <plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <id>deployApp</id> <phase>package</phase> <goals> <goal>run</goal> </goals> <configuration> <tasks> <!--    ant',     --> </tasks> </configuration> </execution> </executions> <dependencies> <dependency> <groupId>org.apache.ant</groupId> <artifactId>ant-jsch</artifactId> <version>1.7.1</version> </dependency> </dependencies> </plugin> </plugins> </build> </profile> </profiles> 


we will lay out the application assembled in the package phase on a remote server.
 <sshexec host="${deployApp.host}" trust="true" username="${deployApp.username}" password="${deployApp.passwd}" command="${deployApp.containerStopCmd}"/> <scp trust="true" password="${deployApp.passwd}" file="${project.build.directory}/${project.build.finalName}.${project.packaging}" remoteTofile="${deployApp.username}@${deployApp.host}:${deployApp.targetWar}" /> <sshexec host="${deployApp.host}" trust="true" username="${deployApp.username}" password="${deployApp.passwd}" command="${deployApp.containerStartCmd}"/> 


Maven needs to be run with the -P deployApp parameter
')
Shl. When using ssh, a rake is possible if the container launch command creates a new process (and this is usually the case). In this case, nohup helps.

Source: https://habr.com/ru/post/114931/


All Articles