Friday, March 23, 2012

Java Program as a Service in Windows

When first time heard about the requirement of running java programs as a Windows service, my mind ran right towards java native (JNI) programming. Took really some time to figure out that there is a simple way to achieve this. That simple way is to use just one ready made jar file for the same occasion.    
Thought of sharing this which I''m sure many test and development boxes setup requires this for some quick testing references.

There is a free utility tool available for this and can be downloaded from Java Service Launcher (JSLWIN).

The description says that it is a lightweight tool to run Java applications as Windows (NT, Win2000, Win2003) services. JSL is released as a ready to use executable. Setup is straight forward including just one executable and one configuration file.

Thought, there are many ways to achieve it, the way I set up was something like below:

1. Download JSL utility and place it in some directory. IN my case it is E:\JSL

2. Created ServiceLauncher class which in turn calls my entry class. Build jar file for the same.

3. JSL.jar need to be placed in lib folder along with the module that need to be made run as a service and dependent jars. ServiceLauncher.jar to be placed in JSL.

4. Change the Java path, JSL path, library path and very importantly working directory information in jsl.ini file

5. Place all the module related files(XML and classes here) in E:\JSL

6. From command prompt, run jsl -install to install the module as a service

7. Start the service from windows service console

8. To remove the sevice from console, stop the service and then run jsl -remove

9. To test before install, run jsl -debug or jsl -run




No comments:

Post a Comment