April 9th, 2012
(written by lawrence, however indented passages are often quotes)
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.