Java is a widely used language in which many programs are being written. Windows is the most widely-used operating system and there are many occasions when a Java program needs to run as a windows service. This article explains how a java program can be run as a windows service. There are many libraries and programs available that can be easily used to wrap a Java program into a windows service. This article describes use of free software Java Service Launcher (for Windows) to run a Java program into a windows service.
Program info and getting the Service Launcer
Note down which class (say com.sample.EntryClass) in the java program is the entry point for the application and has the main method.
Note down the location of the java archive(jar file) which contains the java program.
Analyze C# code coverage
View code coverage in Visual Studio Coverage highlighting and reports
Download Java Service Launcher (JSL) from http://jslwin.sourceforge.net/
Extract the JSL software to a local directory.
Copy JSL.EXE and JSL.INI anywhere on the disk, preferably to the location noted in Step 2 where the java program is located.
Configuring and installing the Service
Configure JSL.ini with the correct parameters. The main parameters to configure are described in following steps.
Set the service name and description by setting the variables 'appname', 'servicename', 'displayname', 'servicedescription' appropriately.
Set the account and password to be used for the windows service using the variables 'account' and 'password.'
Assign the class, method and parameters that will be called when the service is stopped by setting the variables 'stopclass', 'stopmethod' and 'stopparams.'
Set up the parameters to configure the class and method to be called when the service is paused by setting 'pauseclass', 'pausemethod', 'pausesignature' and 'pauseparams.'
Set the java runtime to be used for running the program using by setting the variable ‘jrepath.’
Set the working directory which be used for running the java program by setting the variable ‘wrkdir’. This will mostly be the location noted in Section 1, Step 2.
Configure the java program to be run as a service by setting the variable ‘cmdline’. The class will be the class noted in Step1. Example: cmdline = -cp %P1%\\src com.sample.EntryClass
Alternate to Step 8 above: Use the params variable to configure the java program that will be run as a windows service.
params = 3
Execute the command jsl.exe – install. This installs the service that has been configured in the previous steps.
Start the windows service just installed by using windows service manager.