开始
将服务部署到开发服务器上一般步骤:第一步需要将你的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
了。
- 配置jar
Edit Configurations -> new Configuration -> JAR Application

2.配置scp.jar

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

合并两步操作

- 配置完毕后
Run it!

控制台查看

网友评论