How to run Java application on startup of Ubuntu Linux

本秂侑毒 提交于 2019-12-10 16:48:56

问题


I have a requirement where I need to develop application that reads TCP/IP Socket. 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. Now as per my requirement i have to start execution of this program as soon as Linux system Booted.

Actually I am very novice in Java and Linux Platform, so have few doubts..

  1. Is my Socket Program with no GUI is fine to be run as per my requirement.
  2. How can I write script to run jar on Linux Boot up, I got to know. init.d is meant for this.

回答1:


Ideally you should create a service wrapper for your java application and then make this service run on startup example here.

Use
sudo update-rc.d mytestserv defaults to run your service wrapper on startup on Ubuntu




回答2:


So two things you'll need to do:

First create a small shell script to start your java program from a terminal. As you have packaged as a jar have a look at this, specifically the JAR Files as Applications section.

This may be sufficient: (although you'll want to use the full path to 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. Either putting it in /etc/rc.local, or as you're using Ubuntu, use update-rc.d to start it on boot. See here for a very simple example of using update-rc.d

Hope this helps,

Will



来源:https://stackoverflow.com/questions/22712080/how-to-run-java-application-on-startup-of-ubuntu-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!