[英]How to run Java application on startup of Ubuntu Linux
I have a requirement where I need to develop application that reads TCP/IP Socket. 我有一个要求,我需要开发读取TCP / IP套接字的应用程序。 I successfully made the program as Java program with No GUI means as soon as program runs it starts listening to the Socket and gets the response with the help of Netbeans IDE.
我成功地将程序作为Java程序,没有GUI意味着一旦程序运行它就开始收听Socket并在Netbeans IDE的帮助下获得响应。 Now as per my requirement i have to start execution of this program as soon as Linux system Booted.
现在按照我的要求,我必须在Linux系统启动后立即开始执行该程序。
Actually I am very novice in Java and Linux Platform, so have few doubts.. 其实我是Java和Linux平台的新手,所以很少有人怀疑。
init.d
is meant for this. init.d
就是为了这个。 Ideally you should create a service wrapper for your java application and then make this service run on startup example here . 理想情况下,您应该为您的Java应用程序创建一个服务包装器,然后在此处启动此服务。
Use 采用
sudo update-rc.d mytestserv defaults
to run your service wrapper on startup on Ubuntu sudo update-rc.d mytestserv defaults
在Ubuntu上启动时运行你的服务包装器
So two things you'll need to do: 所以你需要做两件事:
First create a small shell script to start your java program from a terminal. 首先创建一个小的shell脚本,从终端启动你的java程序。 As you have packaged as a jar have a look at this , specifically the
JAR Files as Applications
section. 正如您已经打包为jar,看看这个 ,特别是
JAR Files as Applications
部分。
This may be sufficient: (although you'll want to use the full path to Java) 这可能就足够了:(虽然你想要使用Java的完整路径)
#!/bin/bash
java -jar path_to_jar_file
You should be able to run your script and successfully start your program. 您应该能够运行脚本并成功启动程序。
Once you've got it starting from a script you can use standard linux tools to start the script. 一旦从脚本开始,您就可以使用标准的linux工具来启动脚本。 Either putting it in
/etc/rc.local
, or as you're using Ubuntu, use update-rc.d to start it on boot. 将它放在
/etc/rc.local
,或者当你使用Ubuntu时,使用update-rc.d在启动时启动它。 See here for a very simple example of using update-rc.d
有关使用
update-rc.d
一个非常简单的示例,请参见此处
Hope this helps, 希望这可以帮助,
Will 将
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.