MavenがSSH経由でビルドされた後、リモートサーバー上のWebアプリケーションを更新する

問題



ビルドサーバーまたはローカルマシンを使用してプロジェクトをビルドした後、結果のアプリケーションをテストサーバーにアップロードする必要があります。



解決策



プラグインを使用して、pom.xmlに特別なプロファイルを追加します

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







パッケージフェーズで収集したアプリケーションをリモートサーバーに配置します。

 <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は-P deployAppパラメーターで開始する必要があります



脅威。 sshを使用している場合、コンテナの起動コマンドが新しいプロセスを作成すると、通常はrakeが発生します。 この場合、nohupは役立ちます



All Articles