26.0 Packaging and Starting Agent as a Service


26.1 Overview

26.2 Jars Required for Packaging an SNMP Agent.

26.3 Running the Agent in any Environment

26.4 Packaging the Agent as an NT Service

       26.4.1 Installing the Service

       26.4.2 Starting the Agent as a  Windows Service

       26.4.3 Uninstalling the Service

       26.4.4 Testing the Agent Started as a  Service

       26.4.5 Event Logging


26.1 Overview


Once the agent is deployed, it is ready for packaging. Please follow the steps given in this section to know how to package an SNMP agent.


26.2 Jars required for Packaging an SNMP Agent


To package an SNMP Agent, the following jars are required under the <Agent Toolkit Home>/jars directory:

26.3 Running the Agent in Any Environment


The Agent packaged and deployed can be run provided the above-said jars are available in the <Agent Toolkit Home>/jars directory. To run the Agent in any environment, these jars need to be placed under the specified Agent's directory. For this purpose, a Package Agent option is provided using which all the jars are copied to the Agent directory.


To enable the same,

  1. Select the Build menu from the menu bar of MIB Compiler UI.

  2. Click Package Agent option to avail the facility.

  3. The jars directory is copied under the <Agent Toolkit Home>/snmpprojects/projectname/agent directory with the required jars.  

26.4 Packaging the Agent as a Service


Agent Toolkit supports configuring the developed Agent as a service. By installing this service, WebNMS Agent gets started automatically in the specified port. You need not start the agent every time you log into the system. The steps to be followed in configuring the agent as service are as follows:


26.4.1 Installing the Service


Before moving into installation steps, let us see how any application can be run using Javaservice.


JavaService can be used to run any Java class as a Service in Windows. It can start the service using the standard static void main(String[] args) method, or any other static method that takes a String[] as its only parameter. In its simplest incarnation JavaService will simply terminate the JVM to stop the service, but you can optionally have it call another static method inside the JVM. If JavaService calls another method it will wait either until both the start and the stop methods have returned or until a 30 second timeout has expired before terminating the JVM. JavaService can also optionally redirect the System.out and/or the System.err streams into a file.  


The JavaService executable has no dependencies on any files or directories. This was intentional so that it could easily be used with any Java software. Additionally, it does not have a dependency on the name JavaService.exe. This means that you can, and probably should, rename it to something more appropriate. This can be quite useful when checking the Task Manager to see how much CPU time a particular service is using, or how many threads it has created. Instead of seeing multiple entries for JavaService.exe you see a unique entry for each renamed version of the executable. Follow these instructions to use JavaService with your Java application:

    1. Copy JavaService.exe packaged with Agent Toolkit ( in <Agent Toolkit Home>/subagents/NTutils directory )into a directory appropriate for your application.

    2. You can optionally rename JavaService.exe to something more appropriate.

    3. Start a command prompt and change to the directory where the JavaService.exe is located.

    4. Type 'JavaService.exe -install' followed by the proper parameters, as described below. Be sure to use quotation marks around parameters with spaces (italics signify an application-dependent value):

service_name: The name that you want to use for this service. This is what the service will show up as in the service control manager.

jvm_library: The location of the jvm.dll file that you want to use as your Java Virtual Machine. For Sun's Java 2 SDK, this is usually {JDK_HOME}\jre\bin\classic\jvm.dll or {JDK_HOME}\jre\bin\hotspot\jvm.dll.

jvm_option:  Specify any necessary parameters to pass to the JVM upon invocation. These may include parameters such as "-Djava.class.path=" to specify a classpath . Any parameters that you need to use when invoking the java.exe command tool should be specified here. There is no limit to the number of parameters specified.

For example,

-Djava.class.path=<JavaAgent Home>\snmpprojects\myproject\agent\bin;(also give all the required jars in class path).

-start start_class: The name of the class that you wish to use when starting the service. This must be the fully qualified class name.

For example,


-start com.myCompany.myPackage.WebNMSSnmpAgent


-out out_log_file (optional): A file into which System.out will be redirected. If this parameter is not specified, System.out will not be redirected.


-err err_log_file (optional): A file into which System.err will be redirected. If this parameter is not specified, System.err will not be redirected.


-current current_dir: A directory to use as the current working directory for the service. If this parameter is specified, all relative paths in the service will be relative to relative to the specified directory.

For example,


-current <JavaAgent Home>\JavaAgent\snmpprojects\myproject\agent\bin


-path extra_path (optional): An addition to the path for the service. The specified path will be appended to the system path before the service is started. This can be used to specify where additional DLLs that native libraries are dependent upon can be found.

    //A simple example might look like the following


    C:\users\name\service\bin>JavaService.exe -install "AgentService" c:\JDK\jdk1.3.1_02\jre\bin\hotspot\jvm.dll
    -Djava.class.path=<JavaAgent Home>\snmpprojects\myproject\agent\bin;(also append the required jars here) -start com.myCompany.myPackage.WebNMSSnmpAgent -out c:\user\js.out -err c:\user\js.err -current <JavaAgent Home>\snmpprojects\myproject\agent\bin

26.4.2 Starting the Agent as a Windows Service


Once the service is installed,

26.4.3 Uninstalling the Service

26.4.4 Testing the Agent Started as a  Service


You can test the service Agent by sending queries to the Agent.

26.4.5 Event Logging


JavaService logs both informational events and errors into the Application portion of the NT Event Log. Informational messages include a message 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.

Copyright © 2013, ZOHO Corp. All Rights Reserved.