这个插件可以方便我们 不用靠ssh客户端 去上传重启应用,直接用maven指令去做
上传和重启应用 (配合shell指令,简单的部署其实不需要上传sh脚本到服务器,直接在插件配置
<command>里面写java启动脚本即可),当然如果你的项目是用容器化部署的话那就是另一回事了
主要就是在pom文件里面做些配置
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
..........
<properties>
......
<jar-name>${artifactId}-${version}</jar-name>
<app-name>${artifactId}</app-name>
</properties>
<dependencies>
.................
</dependencies>
<dependencyManagement>
..........................
</dependencyManagement>
<build>
<finalName>${jar-name}</finalName>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.4</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.7.RELEASE</version>
<configuration>
<mainClass>io.kiss.TreefileApplication</mainClass>
</configuration>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<!-- 需要部署的文件 -->
<fromFile>target/${jar-name}.jar</fromFile>
<!-- 部署目录 用户:密码@ip+部署地址:端口 -->
<url><![CDATA[ scp://root:123456@192.168.0.119/opt/${app-name} ]]></url>
<!--shell 执行脚本 -->
<commands>
<!-- 杀死原来的进程 -->
<command>pkill -f ${jar-name}.jar</command>
<command><![CDATA[ps aux|grep java]]></command>
<command>
<![CDATA[ nohup java -jar /opt/${app-name}/${jar-name}.jar > /opt/${app-name}/${app-name}-log.file 2>&1 & ]]>
</command>
</commands>
<!-- 显示运行命令的输出结果 -->
<displayCommandOutputs>true</displayCommandOutputs>
</configuration>
</plugin>
</plugins>
</build>
</project>