Question

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.
Was it helpful?

Solution

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top