maven直接部署springboot的jar包
2018-11-19 本文已影响0人
java修炼
在开发springboot的项目,经常需要部署到服务器上,之前的操作是:打jar包,链接服务器,上传jar包,执行shell。
一套流程下来,至少大概需要十分钟,借鉴了renren开源的部署脚本,直接用maven插件部署,如下:
maven配置
<build>
<finalName>openbbs</finalName>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.8</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<fromFile>target/openbbs.jar</fromFile>
<url>scp://oss:oss@10.5.189.230/home/oss/openbbs/</url>
<commands>
<!-- Kill Old Process -->
<command>bash /home/oss/openbbs/restart.sh</command>
</commands>
<!-- 运行命令 mvn clean package wagon:upload-single wagon:sshexec-->
<!-- 运行命令 mvn package wagon:upload-single wagon:sshexec-->
<displayCommandOutputs>true</displayCommandOutputs>
</configuration>
</plugin>
</plugins>
</build>
服务器上shell脚本:
#!/bin/bash
gmpid=$(ps -ef | grep openbbs.jar | grep -v grep | awk '{print $2}')
if [[ "$gmpid" != "" ]] ;then
kill -9 $gmpid && echo "openbbs.jar stopd "
fi
nohup /usr/java/jdk1.8.0_121/bin/java -jar /home/oss/openbbs/openbbs.jar > /home/oss/openbbs/renren.log 2>&1 &
ps -ef | grep openbbs | grep -v grep