Packages
 In this topic

*Overview

*The Jntsvc Tool

*Example

*Classes

*Hierarchy

 

Packages   PackagesNext
Package com.ms.service   Packages Next

 


About com.ms.service

This package enables you to write a Microsoft® Windows NT® system service in Java. (System services do not work under Microsoft® Windows® 95.) For more information about Windows NT system services, refer to the Microsoft® Platform SDK.

Overview

To create and use a Windows NT service using this package, you must perform the following steps:

  • Create your own service class by deriving it from the Service class.
  • Implement either a default constructor with no parameters or a constructor with a single String[] parameter. This constructor will be used to instantiate the service, and it should perform initialization during ServiceMain.
  • Implement your own versions of service callback methods (the methods that start with handle) to handle the various system service requests.
  • Use the query methods (the methods that begin with can) to determine which controls are accepted by a service (instead of testing the flags returned from getControlsAccepted).
  • Use a built-in assassin to terminate a service that exceeds a time-out period specified by the wait hint value in status updates.
  • Use the jntsvc tool to generate a self-contained, self-installing and uninstalling, redistributable executable for the service.

The Microsoft SDK for Java includes several improvements in the com.ms.service package that were not in version 1.5. The following list describes these improvements.

  1. Multiple services can be run within the same process. (Version 1.5 allowed only one service in a process.)
  2. A new tool, jntsvc, generates self-contained executables for ease of distribution. A generated executable can install or uninstall itself by using the /install or /uninstall options. (Version 1.5 required several binaries to be present, along with a separate install program.)
  3. The service can be started in command line mode, which is useful when starting the service from a debugger. (Version 1.5 required developers to define their own entry point to instantiate the service, and they had to invent a way to simulate control events.)
  4. Arguments can optionally be applied to the service.

The Jntsvc Tool

The jntsvc tool generates a service executable. It is similar in usage and purpose to the jexegen tool. The use of the command file and specification of the class files in combination with the /base and /r options are identical to those used with jexegen. The following command line should be used to generate the executable.


  jntsvc /svcmain:classname [/base:dir] [/out:filename] [/r]
     [/r-] [/v] [@commandfile] files

For detailed information on how to generate a service executable using the jntsvc tool, see the jntsvc section of the Tools Quick Reference.

After you have generated the executable, use the following command line to install, uninstall, or run the executable.


  "executable name" [options] [arguments to service]

The following table briefly describes the available options.
/install Installs the service.
/uninstall Uninstalls the service.
/cmd:service name Runs service service name in command line mode. This is useful when starting and controlling a service under a debugger. Messages that are normally sent to the event log are sent to the console. Service events can be simulated by entering the following commands in the console window.
STOP Sends a SERVICE_CONTROL_STOP event to the service.
PAUSE Sends a SERVICE_CONTROL_PAUSE event to the service.
CONTINUE Sends a SERVICE_CONTROL_CONTINUE event to the service.
SHUTDOWN Sends a SERVICE_CONTROL_SHUTDOWN event to the service.
INTERROGATE Sends a SERVICE_CONTROL_INTERROGATE event to the service.
/username:user name Specifies the account for the service to run as. The default value is "LocalSystem". This option cannot be specified for multiple-service executables.
/password:password Specifies the password of the user name.

Important Note: As of version 2.5, the service information is contained within the generated executable. Therefore, the registry keys under HKLM\System\CurrentControlSet\Services that were used for version 1.5 services are no longer recognized. In version 1.5, certain parameter values were specified when the svcsetup was run. However, with version 2.5, to change the values of these parameters you must regenerate the executable. The only exceptions to this rule are the password and the username parameters, which are now options that you can specify on the generated executable.

Example

The following command line generates an executable for the test service included with the SDK for Java.


jntsvc /svcmain:TestService /eventsource:TestService 
   /base:c:\..\bin\jntsvc TestService.class

Classes

Class Service
This class is a base class for creating Microsoft® Windows NT® system services in Java.
Class ServiceStatus
This class contains information about the state of a service.

Hierarchy

Object
  |
  +--Service
  |
  +--ServiceStatus (Cloneable)

upnrm.gif © 1998 Microsoft Corporation. All rights reserved. Terms of use.