Vert.x打成jar如何在linux开启自启动运行
时间: 2024-02-21 09:00:01 浏览: 92
要在Linux中将Vert.x打成jar并设置自启动运行,可以按照以下步骤进行操作:
1. 首先,将Vert.x打成一个可执行的jar文件,可以使用如下命令:
```
vertx build -cp my.verticle.package -s -o my-verticle.jar
```
其中,`-cp`选项指定Verticle的类路径,`-s`选项表示使用fat jar打包方式,`-o`选项指定输出的jar文件名。
2. 将打包好的jar文件拷贝到Linux系统的某个目录下,例如`/opt/my-verticle/`目录。
3. 编写一个启动脚本,例如`/etc/init.d/my-verticle`,内容如下:
```
#!/bin/bash
### BEGIN INIT INFO
# Provides: my-verticle
# Required-Start: $local_fs $network $remote_fs
# Required-Stop: $local_fs $network $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: My Verticle
# Description: My Verticle Service
### END INIT INFO
APP_NAME=my-verticle
APP_DIR=/opt/my-verticle
APP_JAR=my-verticle.jar
APP_OPTS="-conf config.json"
case "$1" in
start)
cd $APP_DIR
nohup java -jar $APP_JAR $APP_OPTS > my-verticle.log 2>&1 &
;;
stop)
kill `cat $APP_DIR/my-verticle.pid`
rm $APP_DIR/my-verticle.pid
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit 0
```
其中,`APP_NAME`指定应用程序的名称,`APP_DIR`指定应用程序所在的目录,`APP_JAR`指定应用程序的jar文件名,`APP_OPTS`指定应用程序的启动参数。这个脚本可以启动、停止和重启应用程序。
4. 将启动脚本设置为可执行文件,并添加到系统启动项中,可以使用如下命令:
```
chmod +x /etc/init.d/my-verticle
update-rc.d my-verticle defaults
```
现在,当Linux系统启动时,应用程序将自动启动并运行。可以使用以下命令来启动、停止和重启应用程序:
```
/etc/init.d/my-verticle start
/etc/init.d/my-verticle stop
/etc/init.d/my-verticle restart
```
注意,这只是一个简单的示例,实际的情况可能会更加复杂,需要根据实际情况进行调整。
阅读全文
相关推荐

















