I have developed a Java socket server connection which is working fine.
When started from a terminal, it starts from listening from client. But when I close the terminal it stops listening.
I need to continue even though the terminal closed by user from where jar file was started.
How can I run Java server socket application in Linux as background process?
There are several ways you can achieve such a thing:
nohup java -server myApplication.jar > /log.txt– this is pretty straight forward. It will just put the application in the background. This will work but it’s just not a very good way to do so.init.dand required run level with regular start, stop and status commands. I can provide an example if needed.Personally I would go with solution 2 or 3 if you need to use this server in the future and/or distribute it to clients, end users, etc.
nohupis good if you need to run something and have no time to develop more complex solution for the problem.Ad 2:
The best scripts, used by many projects, can be found here.
For Debian/Ubuntu one can use a very simple script based on
start-stop-daemon. If in doubt there is/etc/init.d/skeletonone can modify.