Running Java as a service (daemon) on a Linux machine

(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at: lawrence@krubner.com, or follow me on Twitter.

You can either start the command at the command line, like always, or use a script to launch it:

Overview

Sometimes application have the need to run java application as Linux Service. Aplicatioin needs to start, stop, restart easily. In traditional method, I usually run java application using command line
java -jar applicationame
when I need to restart the application, I will do:
– Find process ID of the application started before
– Kill process kill -9 PID
– start java apps, java -jar applicationname

Besides complicated, this method also has disadvantages such as the when start service for two times there is no prevention if the service running.

Java Service Wrapper

Using Java Service Wrapper, the complected steps above can be simplified.It also support Linux and Windows Platform.

The case study is scheduler will print log every one second. To know about quartz using spring support please check this article

First thing first is download java service wrapper library , I use 3.5.7 version for linux 64 bit. Unzip the file. If you want to use the java service wrapper to production you can remove docs, jdoc, src directory and readme files.
export the application to jar file, you can use you IDE to make it simple.

Post external references

  1. 1
    http://adisembiring.wordpress.com/2011/04/04/running-java-applications-as-a-linux-service/
Source