CentOS7下将jar包注册成系统服务

概述

CentOS7将java的jar包以系统服务的形式在后台运行。

环境准备

系统首先需要安装java环境,将jar包运行成服务本质还是执行java -jar命令的。

配置文件

在/etc/systemd/system/目录下创建helloworld.service文件,内容如下

[Unit]
Description=helloworld service
After=syslog.target
[Service]
Type=simple
ExecStart=/usr/local/java/jdk/bin/java -jar /root/helloworld/helloworld.jar
[Install]
WantedBy=multi-user.target

我运行的是在/root/helloworld/目录下的helloworld.jar文件
注意java命令要写全/usr/local/java/jdk/bin/java,找不到java命令目录的可执行which java命令。
在这里插入图片描述

启动服务

启动服务:systemctl start helloworld.service
查看服务状态:systemctl status helloworld.service
停止服务: systemctl stop helloworld.service
重新启动服务: systemctl restart helloworld.service
设置服务自启动: systemctl enable helloworld.service

猜你喜欢

转载自blog.csdn.net/weixin_39510828/article/details/120201989