1.将jar包放在某目录中,例如/home/ross/earth
2. 创建服务文件
cd /usr/lib/systemd/system/(注意ubuntu可能只有/lib下有system)
vim创建并保存 earth.service
[Unit] Description=earth After=network.target remote-fs.target nss-lookup.target [Service] Type=simple User=root WorkingDirectory=/home/ross/earth ExecStart=/usr/local/share/jdk8/bin/java -jar /home/ross/earth/earth-0.0.1-SNAPSHOT.jar & [Install] WantedBy=multi-user.target
3.设置权限
chmod 775 mongodb.service
systemctl daemon-reload
4.设置自启动
systemctl enable earth.service
5.启动服务
systemctl start earth.service