[an error occurred while processing this directive] [an error occurred while processing this directive]
Jeff Vannest's Weblog

« "Where Does Quality Come From? (The Stunning Conclusion Continued)" | Main | "Why Structure?" »

June 09, 2005

Java Monitors in SQL*LIMS 4.1

Java is a language that has gained much popularity. This is partially due to its ability to run on most computing platforms. However, if you try to run a java program as a Windows monitor on the application tier of a SQL*LIMS version 4.1 installation, you will notice that it doesn't seem to work. In this article, I'll demonstrate how to run a java program as a Windows service using a helper program already delivered with the SQL*LIMS software.

There are at least two ways a program written in java can run as a Windows service. I will describe the first method, although it is not the one I recommend: The java program can be compiled into a Windows native executable. While this is functional, it typically requires an expensive development suite like Borland JBuilder Enterprise Edition, and it means that if you intend to use the same java program on multiple computing environments, you'll have to re-test and re-validate each OS executable that you produce. Further, it means that future modifications also require an expensive development suite. Unless there is compelling reason, I do not recommend this method.

The method I prefer is to use a helper program delivered with SQL*LIMS. Using this method keeps the java files in their original form, and works just as effectively. From the SQL*LIMS server CD, locate the file named srunner.exe. Next, create three text files as follows:

File #1: create_service.bat

    @echo off
    ECHO .
    ECHO This file is used to create a Windows service using
    ECHO a serviceprops file and srunner.exe, which is used to
    ECHO install, remove, and run the program as a Windows service.
    ECHO .
    ECHO .
    SET /P serviceprop=Enter service properties file:
    .\srunner %serviceprop%
    ECHO .
    ECHO .
    ECHO Installation complete.
    ECHO .
    PAUSE

File #2 remove_service.bat

    @echo off
    ECHO .
    ECHO This file is used to delete a service using its internal
    ECHO Windows service name. This name may not be the one displayed
    ECHO in the Services dialog.
    ECHO .
    ECHO .
    SET /P serviceprop=Enter service name:
    .\srunner -r %serviceprop%
    ECHO .
    ECHO .
    ECHO Removal complete.
    ECHO .
    PAUSE

File #3 service.serviceprops

    My_Monitor
    My Monitor
    Manual

    java
    -cp .;.\myJar.jar com.my.company.myClass
    C:\sqllimssvr\v4_1_0\myMonitor\Bin
    <END>

The first two batch files are self explanatory; they are used to create and remove your new monitor, which is being installed as a Windows service. The first batch file will prompt for a filename, which is the name of File #3. The second batch file fill prompts for the internal name of the Windows service to remove. Both files should be executed with the Windows Services dialog closed, since Windows is quirky about adding and removing services with it open.

The third file bears some explanation, for this is where you're going enter the information about your new monitor. Here's a version of the file with line numbers:

   1. My_Monitor
   2. My Monitor
   3. Manual
   4.
   5. java
   6. -cp .;.\myJar.jar com.my.company.myClass
   7. C:\sqllimssvr\v4_1_0\myMonitor\Bin
   8. <END>

Line number 1 is the internal name of the WIndows service, and must contain no spaces.

Line number 2 is the external name of the Windows service, the one you see in the Services dialog.

Line number 3 indicates how the service will start, and the options are Manual, Automatic, and Disabled.

Line number 4 can be left blank. If there is a service upon which your new monitor depends, you can enter its internal Windows service name, otherwise, just leave line 4 blank.

Line 5 is the name of the command to execute, which in this case is the java virtual machine. Specifying "java" all by itself will choose whichever JVM is the system default. If you wish a specific JVM to execute - for example, your new monitor is only validated on java version 1.3.1 - then you can specify the full path name to the java.exe program.

Line 6 lists all of the parameters you wish to send to the java program. In this example, I have specified a java classpath pointing to the current directory and to a jar file named myJar.jar. The next parameter indicates that I wish to start the execution of the "myClass" class in the "com.my.company" package.

Line 7 indicates the folder from which the Windows service will execute, which in this example, is a custom Bin folder off the SQL*LIMS server folder.

Line 8 must have a single word, "<END>", indicating the end of the file.

Once you have configured the service.serviceprops file, simply execute the create_service.bat, and your new monitor will run as a Windows service.

By the way, if you do not have access to the SQL*LIMS server CD and the srunner.exe program, you can download a similar program from the same author at the KC Multimedia and Design Group's page for "Running a Java 2 Application as an NT Service".

Posted by Jeff Vannest at June 9, 2005 05:53 PM

Trackback Pings

TrackBack URL for this entry:
http://www.jandrconsult.com/cgi-bin/mt/mt-tb.cgi/60

Comments

Post a comment

Thanks for signing in, . Now you can comment. (sign out)

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)


Remember me?


 
[an error occurred while processing this directive]