在IDEA中如何将Spring boot项目打包成可执行的jar包并发布到linux服务器

1,idea里面通过Maven,选中skip test模式,
右键运行clean, 然后package或install

2,把kr-pm-0.0.1-SNAPSHOT.jar上传到linux某个目录,比如/usr/app


3,cd usr/app

<1>首次部署当前程序需要在对应的文件夹中执行以下命令
a.启动程序
nohup java -jar kr-pm-0.0.1-SNAPSHOT.jar
--spring.profiles.active=prod > /dev/null 2>&1 &

返回24392  进程号
b.退出 ctrl + c


<2>非首次部署当前程序需要在对应的文件夹中执行以下命令
a.捕获上一个版本程序的进程
ps -ef|grep kr-pm-0.0.1-SNAPSHOT.jar


b.杀死对应的进程 kill 进程号
kill 24392
杀死进程号后,
在执行上一步ps -ef|grep kr-pm-0.0.1-SNAPSHOT.jar看看进程是否存在

若返回 no such process,
则采用
ps aux |grep spring | xargs kill -9
肯定可以杀死进程


c.启动程序
nohup java -jar kr-pm-0.0.1-SNAPSHOT.jar --spring.profiles.active=prod > /dev/null 2>&1 &

d.退出 ctrl + c


或者kill -9  进程号

猜你喜欢

转载自lanyan-lan.iteye.com/blog/2413071