1.装置jdk

apt install openjdk-11-jdk

2.创立服务配置文件

vim /ect/systemd/system/my_service.service

追加以下内容

[Unit]Description=My Java Service[Service]User=ubuntuWorkingDirectory=/home/ubuntu/serverExecStart=/usr/bin/java -jar /home/ubuntu/server/main.jarSuccessExitStatus=143TimeoutStopSec=10Restart=on-failureRestartSec=5[Install]WantedBy=multi-user.target

3.更新、运行、启动服务配置

systemctl daemon-reloadsystemctl enable my_service.servicesystemctl start my_service.service