Windows Installer, Java Installer, Freeware Installer
Home|Contact|Site Map|TOC|Search
Download  Features   Java  Licensing  Purchase  Testimonials  Support  Forums

Creating a Java Service Installation

Let's say that we want to create a Windows Installer package for the included Java Service example. This tutorial will present in detail how to achieve this goal. In order to replicate it on your own machine, you need to have a (latest) Sun JDK installed.

Before you start the tutorial download and unzip the Java Service Example. It contains all the files necessary to accomplish this tutorial.

  1. Prepare a Java application for running as a service
  2. Create the project
  3. Enter the Product Details
  4. Set the Install Parameters
  5. Add the Installation Files
  6. Define the Java Products
  7. Define the Service
  8. Build
  9. Run, test and remove

Prepare a Java application for running as a service

You have the choice of using the supplied example application or making your own. In order for a Java application to work correctly as a service you must implement 2 methods in its main class:

public static void main(String argv[])
{
  // implementation goes here
}

public static void stop()
{
  // implementation goes here
} 

The main() method will be called when the service starts and the stop() method will be called when service must stop or the computer is shutting down.

Create the project

Start Advanced Installer by selecting it from the "Start" menu. Launching Advanced Installer automatically starts a new installation project. Choose "Java Application" as the project type.

New Project

Save A good idea is to save and name the project at this point. Use the "Save" menu item under the "File" menu or the Ctrl+S keyboard shortcut and let's name it javaserviceexample.aip.

Enter the Product Details

Product Details

Please note that these details are completely fictive.

Set the Install Parameters

Install Parameters Get to the Install Parameters page by clicking "Install Parameters" on the left side page menu. We won't change anything here, leaving everything to their default values.

Add the Installation Files

Files and Folders Go to the Files and Folders page by clicking on "Files and Folders" on the left side page menu.

Add Folder Right click "Application Folder" and select "Add Files". Browse to where you unzipped the Java Service example then go to the lib folder and select the Java Services example jar archive "javaservice.jar". Click Ok.

Files, Folders and Shortcuts

Define the Java Products

Java Products Go to the Java Products page by clicking on "Java Products" on the left side page menu.

New Java Product Create a new [ Java Product ] by clicking on the New Product toolbar button. Let's call it javaservice.

Java Products

Click on the [ Add JAR(s)... ] button and browse to and select the javaservice.jar file. Click Ok.

Edit the Main class to: com.caphyon.service.JavaService.

At the application type select "Win32 Service".

Product Settings

Now a new file has appeared in the Files and Folders Page: javaservice.exe.

Define the Service

Services Go to the Services page by clicking on "Services" in the Project Details.

Install a new service

New Service Click on "Services to Install" and select "New Service Installation". In the "Choose Instalation Dialog" click on "Application Folder" and select "javaservice.exe".

New Java Service

Enter service properties

Leave Service Name unchanged.

Edit the Display Name: Java Service Example.

Edit the Description: This a Java Service Example.

Leave the Service Parameters, Service context and Service Account unchanged.

Installed Service Properties

Setup the control actions

New Service Control Operation Right click on "Control Action" and select "New Service Operation".

Edit the Service Name to: javaservice.exe.

Leave anything else unchanged.

Sevice Control Parameters

Build

Build Click on the [ Build ] toolbar button.

Run, test and remove

Click on the [ Run ] toolbar button to run and test the MSI you created. After installation you should have a new service installed.

To test the application open console and enter the following command: telnet localhost 4444. You should see:

Java Service is running
                        
Connection to host lost

You also can build Java Service Example msi package using ant. Open a console window and change current directory to the directory where you unzipped the Java Service example archive. Execute the following command: ant msi.

To remove the installed package, simply Run it again and select Remove. That's it!

Privacy Policy | Windows Installer | Search Engine Ranking | Link Analyzer