Running Java Applications as a Linux Service


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.

Manage Artifact

Go to wrapper_home,
copy application jar to wrapper_home/jsw.jar
copy application configuration file such:, application-context.xml to wrapper_home/
copy application library to wrapper_home/lib


open wrapper configuration file wrapper_home/conf/wrapper.conf and change some configuration file:

Wrapper Class

Configure application jar file

Configure application lib dependency

Configure application main class

Configure Service Description

# Name of the service
# Display name of the service
wrapper.displayname=Java Service Wrapper Example
# Description of the service
wrapper.description=Java Service Wrapper Example Description

Go to wrapper_home/bin change testwrapper file name to jws to make it more explicit to service name.

Test Application

Go to wrapper_home/bin
install service: sh jws install
start service: sh jws start

To check the start service successfully executed, check log the log file wrapper_home/logs/wrapper.log

restart service: sh jws restart
stop service: sh jws stop


download spring quartz scheduler source code.

5 thoughts on “Running Java Applications as a Linux Service

  1. Peter February 9, 2012 / 12:52 pm

    What are the pricing details of it? Seems very expensive if you have to distribute as part of linux package of your hardware

  2. kink in my neck July 4, 2013 / 5:06 pm

    Hello! This is kind of off topic but I need some help from an established blog.
    Is it hard to set up your own blog? I’m not very techincal but I can figure things out pretty fast. I’m thinking about creating
    my own but I’m not sure where to start. Do you have any points or suggestions? Thank you

  3. whatsapp for windows July 11, 2013 / 11:10 pm

    I constantly spent my half an hour to read this webpage’s posts everyday along with a mug of coffee.

  4. candy crush cheats August 7, 2013 / 1:11 pm

    whoah this blog is wonderful i like studying your posts.
    Keep up the great work! You know, lots of individuals are hunting around for
    this info, you can help them greatly.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s