[英]How do you run a jar file on boot (Ubuntu 11.10)?
I'm using Ubuntu 11.10. 我正在使用Ubuntu 11.10。 I've written a simple listener application in Java which runs properly (tested).
我已经用Java编写了一个简单的侦听器应用程序,该应用程序可以正常运行(经过测试)。 Basically this java application in a loop that waits for an event every 60 seconds.
基本上,此Java应用程序处于一个循环中,每60秒等待一次事件。 After successfully jar-ing this file, I'm able to execute the file using
成功震荡此文件后,我可以使用
/usr/bin/java -jar /home/testuser/MyApp.jar
What I want to do is a create a shell script that starts this application when Ubuntu boots. 我想要做的是创建一个Shell脚本,当Ubuntu启动时启动该应用程序。 My autostart.sh script is really simple:
我的autostart.sh脚本非常简单:
#!bin/bash
/usr/bin/java -jar /home/testuser/MyApp.jar
Then I use the following commands to put it in the init.d directory: 然后,我使用以下命令将其放在init.d目录中:
#: sudo cp /home/testuser/autostart.sh /etc/init.d
#: chmod 777 /etc/init.d/autostart.sh
#: sudo update-rc.d /etc/init.d/autostart.sh defaults
Then I restart and use top to see if Java is running, but I dont see this. 然后,我重新启动并使用top来查看Java是否正在运行,但是我没有看到这一点。 Does anyone know what the best way to implement this?
有谁知道实现此目标的最佳方法是什么?
Using "ls -l /etc/rc?.d/*autostart" I get: 使用“ ls -l /etc/rc?.d/*autostart”,我得到:
@hovanessyan: my output for that command is - @hovanessyan:我对该命令的输出是-
lrwxrwxrwx 1 root root 17 2012-03-19 14:26 /etc/rc0.d/K20autostart -> ../init.d/autostart
lrwxrwxrwx 1 root root 17 2012-03-19 14:26 /etc/rc1.d/K20autostart -> ../init.d/autostart
lrwxrwxrwx 1 root root 17 2012-03-19 14:26 /etc/rc2.d/S20autostart -> ../init.d/autostart
lrwxrwxrwx 1 root root 17 2012-03-19 14:26 /etc/rc3.d/S20autostart -> ../init.d/autostart
lrwxrwxrwx 1 root root 17 2012-03-19 14:26 /etc/rc4.d/S20autostart -> ../init.d/autostart
lrwxrwxrwx 1 root root 17 2012-03-19 14:26 /etc/rc5.d/S20autostart -> ../init.d/autostart
lrwxrwxrwx 1 root root 17 2012-03-19 14:26 /etc/rc6.d/K20autostart -> ../init.d/autostart
Create an upstart job and set the appropriate run level(s). 创建一个暴发户作业并设置适当的运行级别。 Look at the other jobs in
/etc/init
with the .conf extensions for examples. 请查看
/etc/init
带有.conf扩展名的其他作业作为示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.