我试图让一个 .jar 文件在 Ubuntu 机器上启动时运行,但我没有任何进展。 我试过这里的说明 https://askubuntu.com/questions/99232/how-to-make-a-jar-file-run-on-startup-and-when-you-log-out ,并且我尝试使用 Upstart 网站和食谱中的信息,但它们没有用。我已经尝试过旧的 SysV 和新的 Upstart 方法,但它们都不会在系统启动时启动 .jar。
这是运行 .jar 的 shell 脚本
#!/bin/bash
cd /home/dev/TransformationService/
java -jar TransformationServer.jar
SysV启动方式文件
#!/bin/bash
# Transformation Server
#
# Description: Transforms incoming messages on a given port and forwards them
case $1 in
start)
/bin/bash /usr/local/bin/ServerStart.sh
;;
stop)
/bin/bash /usr/local/bin/ServerStop.sh
;;
restart)
/bin/bash /usr/local/bin/ServerStop.sh
/bin/bash /usr/local/bin/ServerStart.sh
;;
esac
exit 0
UpStart 方法
# transformationserver - transforms incoming http messages, and redirects them
#
# This service intercepts incoming http messages on a given port, and
# transforms them into an acceptable format in order to be received
# by a 3rd party service
start on runlevel [345]
stop on runlevel [!2345]
respawn
script
exec /bin/bash /home/ubuntu/TransformationServer/ServerStart.sh
# Also trying the below as well
#exec /bin/java -jar /home/ubuntu/TransformationServer/TransformationServer.jar
end-script
是否可以在使用这些方法中的任何一种方面有更多经验的人在这里查看我的文件,并可能为我指明正确的方向?需要这项服务,这样我们公司的系统才能成功接收来 self 们一位客户的通信。
提前致谢。
最佳答案
你使用 crontab 怎么样?
作为您希望 jar 运行的用户,运行此命令:
crontab -e
添加行:
@reboot /path/to/your/ServerStart.sh
保存它。这将使它在服务器重新启动后恢复时运行您的 shell 脚本。
这是您的 crontab,您可以通过 man crontab 或维基百科页面了解所有相关信息:https://en.wikipedia.org/wiki/Cron
关于java - 在系统启动时在 Ubuntu 上运行 Jar 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17799431/