JavaService - Source Code
 

Contents

Overview
Build Instructions
File Descriptions

Overview

This documentation applies to building this product using Visual C++ 6.0. In addition, you must have the lib file and header files for a JNI 1.2 compliant Java Virtual Machine, such as Sun's Java 2 SDK version 1.4. This documentation assumes you are using a version of the Sun Java 2 SDK.

The result of building this product is a Win32 executable called JavaService.exe.
For test purposes, a debug instance is also available (JavaServiceDebug.exe)

Build Instructions

  1. The first step is to configure Visual C++ to be able to find the JNI lib file and header files.
    1. Go to 'Tools->Options' on the menu.
    2. Go to the 'Directories' tab on the dialog.
    3. Choose 'Show directories for: Include Files'.
    4. Add the directory '{JDK_HOME}\INCLUDE' to the list.
    5. Add the directory '{JDK_HOME}\INCLUDE\WIN32' to the list.
    6. Choose 'Show directories for: Library Files'.
    7. Add the directory '{JDK_HOME}\INCLUDE\LIB' to the list.

    Visual C++ should now be properly configured to compile binaries using JNI.

  2. Either open the project included with the distribution (JavaService.dsp) or create a new one. If you are creating a new project, be sure to choose 'Win32 Console Application' as the project type, and choose 'An Empty Project' when asked what files to automatically generate.

  3. Make sure the project contains the following files:
    • Source Files
      • JavaInterface.cpp
      • ServiceInterface.cpp
      • JavaService.rc
    • Header Files
      • JavaInterface.h
      • ServiceInterface.h
      • Messages.h
      • VersionNo.h
    • Resource Files
      • Messages.mc (note: see file description for build instructions if you change this file)
      • JavaService.rc2
  4. You should now be able to build the JavaService.exe file by going to 'Build->Build JavaService.exe' on the menu. (note: Release build and Debug build options are defined separately)

File Descriptions

ServiceInterface.cpp
This file contains the code to interface with the command-line and the NT service subsystem.

ServiceInterface.h
This file contains prototypes for global functions in the ServiceInterface module.

JavaInterface.cpp
This file contains the code to create and interface with the Java Virtual Machine.

JavaInterface.h
This file contains prototypes for global functions in the JavaInterface module.

VersionNo.h
This file contains constant definitions of the application version number, which are used to generate the built-in VERSIONINFO resources for the program, as well as for -version reports.

Messages.mc
This file contains the text version of the message resources that get compiled into the final binary. These resources are used by the Event Viewer to display formatted messages that are logged to the NT event log. Messages should be formatted like the following example:

MessageId=0x0000
Severity=Informational
Facility=Application
SymbolicName=EVENT_IDENTIFIER
Language=English
Example message %1 with two parameters %2.
.

If the Messages.mc file has been changed since it was last compiled, it must be manually recompiled before the final binary is built. Use the following steps to compile the Messages.mc file:

  1. Open a command prompt and run the 'VCVARS32.BAT' file that is installed with Visual C.
  2. Move to the directory containing the JavaService source code.
  3. Run the command 'mc Messages.mc' to generate the files MSG00001.bin, Messages.h, and Messages.rc.

Messages.h
This file contains the identifiers used when logging messages to the event log. It is automatically generated from the Messages.mc file.

Messages.rc
This file is a resource script for the message resources. It is automatically generated from the Messages.mc file and gets included by the JavaService.rc file at compile time.

MSG00001.bin
This file contains the binary version of the message resources. It is automatically generated from the Messages.mc file.