Ubuntu设置jar包开机自启
时间: 2023-08-07 08:29:55 浏览: 627
要在Ubuntu中设置jar包开机自启,可以按照以下步骤进行操作:
1. 在你的Ubuntu系统上创建一个新的启动脚本,例如`/etc/init.d/myapp`,并将其权限设置为可执行,命令为:
```
sudo chmod +x /etc/init.d/myapp
```
2. 打开`myapp`文件并添加以下内容:
```
#!/bin/sh
### BEGIN INIT INFO
# Provides: myapp
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/stop myapp
### END INIT INFO
# Change directory to the location of your jar file
cd /path/to/your/jar/file
# Start the jar file
java -jar yourjarfile.jar
```
注意:需要将`/path/to/your/jar/file`替换为你的jar文件所在的完整路径。
3. 保存并关闭文件。
4. 将启动脚本添加到系统启动项中,命令为:
```
sudo update-rc.d myapp defaults
```
5. 重启系统以测试自启动是否生效。
现在,你的jar应用程序应该已经可以在Ubuntu系统启动时自动启动了。
阅读全文
相关推荐

















