SourceForge.net Logo

Java Service Launcher (for Windows) JSL 0.99p - December 2015

Download here or contact the author at  Michael@Roeschter.com

How To start my java programm as a service

Quick start:
  • Copy JSL.EXE and JSL.INI somewhere on your disk.
  • Modify the JSL.INI to reflect your desired settings. Ecspecially classpath and command line parameters.
  • Run jsl.exe -install
  • Start it in the NT service manager or by calling NET start "TelnetEcho"
Setup:
The jsl executable will look for an ini file with the same name as the executable in it's directory. Copy both to a location of your choice (possibly where your java app is located).

Initialization file:
The initialization file is both necessary for setup and running the service. Don't remove it after you have installed the service.
It contains parameters for both service setup and java application.

See here for an example

Command line options
Calling jsl.exe without parameters gives an overview of the available options.

-install

Install the service in the NT service manager. Service is not started immediately, though it will start automatically when NT is rebooted.
Start the service from command line with NET START <APPNAME>.

-configure
Will reconfigure

-remove

Remove an installed service. This may fail if the service is still running.
Stop the service from command line with NET STOP <APPNAME>.

-debug

Run the application from command line for debugging purposes. A service need no be installed.

You can simulate and test service stop, pause and continue behavior on the command line by starting with -debug option. Use CTRL-C for stop service, CTRL-BREAK will toggle between pause and continue service.

-run

Run the application from command line purposes. No -Dservice parameters will be passed.

Stopping a service
There are two ways supported for stopping a Java application:
A) JSL can call a static method to signal the shutdown request. This is configured in the configuration file:

stopclass=java/lang/System

stopmethod=exit
stopsignature=(I)V
As you see above the simplest (and the default) is to call System.exit(0). If you want to do some shutdown install a shutdown hook in the JVM or simple call some other static method of your own design. Just don't forget to actually call System.exit() in the end else JSL and the Service Manager will be confused and might not report the sevice as stopped.

B) The former and now deprecated way is to open a TPC/IP connection on the port specified as "stopport" in the service ini file.
The most simple way to take advantage of this feature is to use the ServiceStopper class and Stopable interface as presented in the TelnetEcho example. The ServiceStopper will only accept connections from the localhost, so your service cannot be shutdown remotely.
You can avoid implementing the Stopable interface by using the class SimpleStopper.

This is the most simple service which simple does nothing until stopped.

public static main (String[] argv)

{
ServiceStopper.stop( new SimpleStopper() );
}

If the functionality supplied by ServiceStopper is insufficient for your needs, you might want to implement your own handler code for stopping the service. The port is passed to the java application via a -Dservice.stop.port=<PORT> parameter which is prepended to the parameters given in the INI file. You can read it back by a call to System.getProperty( "service.stop.port" )