JavaService - Technical Operations

The full set of command and parameters available from JavaService is likely to be of interest to more technical users, either when integrating Java applications with this utility, or when investigation further options for an existing usage.

Command Summary

The commands listed below are self-documented within the application, if invoked from a Windows command prompt with the JavaService -help command.

-help
(or -?) Lists the commands available from JavaService
-version
Outputs the built-in version number of the JavaService program
-license
(or -licence) Outputs the LGPL licensing text covering the program
-install servicename
Installs the named service with specified configuration options
-queryconfig servicename
(or -query) Displays confguration details for the installed Java service
-status servicename
Displays current execution status of the named Java service
-uninstall servicename
Removes definition of the specified Java service

Available Operations

Service Installation

The main command function needed from JavaService is the ability to install a Java application as a Windows system service.

From a Windows command prompt, or a suitably defined script file, enter the command:
JavaService -install
Followed by the relevant parameters as described below. Ensure that quotation marks are used around an parameters that contain spaces to avoid run-time failures.

Example Command

A simple example might look like the following:

JavaService.exe -install "My Service" c:\j2sdk\jre\bin\server\jvm.dll -Djava.class.path=c:\app\classes.jar -start com.my.ExampleClass -err c:\app\stderr.txt

This would create a service that, when started, would create a JVM from the JDK in c:\j2sdk using a classpath set to be c:\app\classes.jar. It would then call the main method of the com.my.ExampleClass class with a String array of length 0 (no parameters). Anything written to System.err would be redirected into the file c:\app\stderr.txt.

Technical Tip

Especially when running more than one Java application as a service, you may find it useful to copy and rename the program file before each use to indicate the application name concerned.

In this way, the Windows Task Manager will show the relevant program name in its list of processes, where AbcService.exe and XyzService.exe would be clearer than two entries for JavaService.exe if renaming is not used.

Starting a Service

Once a service has been installed with a given name, there are three ways in which service execution may be started.

Automatic Startup

If a service is specified with automatic startup, it will be executed when the Windows system is booted and started up. Automatic startup mode is the default when installing services using JavaService. This can be overridden with the -manual option on the install command. It may also be changed using the Windows administrative tools, to switch from automatic to manual startup mode.

Net Start Command

The standard Windows command for starting system services is the 'net start' command. This can be issued from a Windows prompt, specifying the service name as shown in the following example:
net start myservice

Service Management Tool

Windows provides a system management utility to provide control of system services from a graphical front-end. This is available from the Start Menu or Control Panel Administrative Tools list, as the Service utility.

This utility lists all configured services, indicating their startup mode and current status. Tasks and menu options are available to start or stop service execution, or to disable a service entirely.

Stopping a Service

There are two ways in which a currently executing service may be stopped.

Net Stop Command

The standard Windows command for stopping executiong of system services is the 'net stop' command. This can be issued from a Windows prompt, specifying the service name as shown in the following example:
net stop myservice

Service Management Tool

The Windows Services utility is available from the Start Menu or Control Panel. It displays the status of all configured services and provides tasks and menu options to stop services that are currently running within the system.

Removing a Service

JavaService provides a command to enable configuration of a Java service to be correctly removed from the system.

From a Windows command prompt, or a suitably defined script file, enter the command:
JavaService -uninstall service_name
Where:

Version Number Query

The version number of the JavaService software is available using either of two methods on the Windows platform.

One method is to enter the command JavaService -version
when the program will display version and copyright information.

An alternative method is to locate and select the JavaService.exe file in Windows Explorer and select the Properties option from the right-click menu, or press Alt+Enter as a shortcut.
The version number and copyright information for the program can then be viewed from the property tabs displayed by Windows.

Registry Settings

JavaService stores the configuration information for installed services in the Windows system registry, under the location:

HKEY_LOCAL_MACHINE\ SYSTEM\ CurrentControlSet\ Services\ {SERVICE_NAME}\ Parameters

The following keys are used and may be changed after service installation to modify the behaviour of the service.

Current Directory - The current working directory for the service.

JVM Library - The location of the jvm.dll library to use to create the Java Virtual Machine.

JVM Option Count - The number of option to pass to the JVM when creating it.

JVM Option Number n - An option to pass to the JVM. n ranges from 0 to "JVM Option Count" - 1.

Path - Extra path information that will be appended to the system path before the service is started.

Start Class - The class to use to start the service.

Start Method - The static method to call on the "Start Class" to start the service.

Start Param Count - The number of parameters to pass to the "Start Method" to start the service.

Start Param Number n - A parameter to pass to the "Start Method" to start the service. n ranges from 0 to "Start Param Count" - 1.

Stop Class - The class to use to stop the service. If this key is absent, the process containing the JVM will simply be terminated when the service is stopped.

Stop Method - The static method to call on the "Stop Class" to stop the service.

Stop Param Count - The number of parameters to pass to the "Stop Method" to stop the service.

Stop Param Number n - A parameter to pass to the "Stop Method" to stop the service. n ranges from 0 to "Stop Param Count" - 1.

System.err File - A file into which System.err will be redirected. If this key is absent, System.err will not be redirected.

System.out File - A file into which System.out will be redirected. If this key is absent, System.out will not be redirected.

Shutdown Timeout - The number of milliseconds to allow for the Java Stop method to complete, before timeout and JVM forced termination.

Event Log Messages

JavaService logs both informational events and errors into the Application portion of the Windows Event Log.

Informational messages record events when the service is started and one when it is stopped. Error messages may be logged because of a configuration problem or other system error.

If you are having trouble getting JavaService to run your application, you should first check the Application portion of the Event Log to see if any errors were reported. Additionally you can check the redirected System.err file, as any Java exceptions will be written there by the Virtual Machine of the run-time environment.

Note that if the JavaService executable used at service installation is deleted from the system, the content of the event log messages cannot be displayed by the Event Viewer. Instead, the message id value will be shown with some Microsoft error text, plus any parameter values that would normally be included in the formatted message text.