IDEA一键部署到开发服务器

开始

将服务部署到开发服务器上一般步骤:第一步需要将你的war包(或者其他)scp到服务器的指定位置上;第二步在将服务通过一定的shell命令执行部署的步骤。

jenkins可以完美的处理以上步骤,不用jenkins还有其他轻量级的方法处理吗?

也是对应的两步:第一步得有能自动化scp的工具。第二步有自动化执行远程脚本的工具。如果能将这两步集成到IDEA中变成一个按钮的操作,那就非常舒服了。

工具

scp工具

首先考虑到的就是用scp命令,linux环境可以直接用自带的scp命令,Windows环境网上也有相应的scp.exe,但是命令行没有现成自动输入密码的解决方案,配置成本高。

何不利用java跨平台特性的手写一个scp.jar呢?

说干就干

https://gitee.com/zkdcloud.cn/scp/releases

java -jar .\scp-1.0.0.jar -help

usage: scp -help
 -d,--dst_path <arg>   the dstPath of remote
 -h,--host <arg>       the host of remote server
 -help                 usage help
 -P,--port <arg>       the port of remote server
 -p,--password <arg>   the password of remote server
 -s,--src_path <arg>   the srcPath of local
 -u,--user <arg>       the user of remote server

非常简单的scp工具就诞生了,包含scp所需要的基本参数,执行命令如下:

java -jar .\scp-1.0.0.jar -s "D:\abc-project\target\abc.war" -h "192.168.27.112" -u "root" -p "111111" -d "/tmp/abc.war"

shell-exec工具

远程执行shell命令的工具同理。

https://gitee.com/zkdcloud.cn/shell-exec/releases

java -jar .\shell-exec-1.0.0.jar -help
Missing required options: h, u, p, c
usage: scp -help
 -c,--command <arg>    will exec command
 -h,--host <hello>     the host of remote server
 -help                 usage help
 -P,--port <arg>       the port of remote server
 -p,--password <arg>   the password of remote server
 -u,--user <arg>       the user of remote server
java -jar .\shell-exec-1.0.0.jar -c "mv /tmp/abc.war /home/tomcat/webapps/ && /home/tomcat/bin/startup.sh" -h 192.168.27.112 -u root -p 111111

IDEA上一键部署

有了这两个工具,剩下的就是集成进去IDEA了。

  1. 配置jar Edit Configurations -> new Configuration -> JAR Application
3432069-3b9bb2968c68f3e2.jpg
image

2.配置scp.jar


3432069-189b6c84fe003258.jpg
image

3.同理配置shell-exec.jar

4.构建新增配置Edit Configurations -> new Configuration -> Compound,将这两步操作合成一步操作
添加compound

3432069-78202a758bd9253f.jpg
image

合并两步操作


3432069-d8e9f7968b18c2f2.jpg
image
  1. 配置完毕后 Run it!
3432069-7929c2887f3dea78.jpg
image

控制台查看


3432069-5dff6dff7eb75ed6.jpg
image

转载于:https://www.jianshu.com/p/e6cf392347d3

猜你喜欢

转载自blog.csdn.net/weixin_33873846/article/details/91181648