Monitor Integration in Java

This article will describe how to integrate the Analytics Java monitor in a Java application.

The integration consists of three steps:

  1. Add the monitor-library to your project
  2. Create and start the monitor

Before getting started you must also have created an application so you have a product id. You will need that in the integration. Read more about how to Add Analytics to Your Application.

Requirements

These are the requirements for Analytics to work with your Java application:

  • Java Runtime Edition: JRE 1.6 and above

Step 1: Add the monitor-library

The monitor is added as an external archive to your Java project.

You should place the downloaded analyticsmonitor.jar monitor file somewhere inside your Java application folder and add it to the build path. In an Eclipse project you browse to the jar-file like so:

Point the build path to the location of the monitor JAR file

When you have successfull pointed to the monitor file, you project references will include a reference to the analyticsmonitor.jar monitor file:

The monitor library must be part of the Referenceed Libraries

Step 2: Create and start the monitor

Next step is creating and starting the monitor, as described in the Monitor Integration article. After that, when running your Java application, you will see data from it appear in the Analytics client dashboard.

Precisely how you wish to use the monitor into your source is up to you and your coding-preferences. Your application needs to create a monitor object and it needs to call start and stop on that object and later on you will most likely want to call other API methods on it, too.

For simplicity, we will show here how to create and start the monitor in the simplest possible manner:

Demo example of integrating the Java monitor into a simple application

package telerik.analytics.sample.java;

import eqatec.analytics.monitor.AnalyticsMonitorFactory;
import eqatec.analytics.monitor.IAnalyticsMonitor;
import eqatec.analytics.monitor.Version;

public class Demo {
  private static IAnalyticsMonitor _monitor; 

  public static void main(String[] args) {
    try {
      // Start the monitor when your application starts
      String productId = "########### YOUR ANALYTICS PRODUCT KEY GOES HERE #################";
      Version version = new Version("1.0.0");
      _monitor = AnalyticsMonitorFactory.createMonitor(productId, version);
      _monitor.start();
      /* Your program goes here .... */
    } catch (java.net.URISyntaxException e) {
      e.printStackTrace();
    }
    finally {
      // Best practice is to stop the monitor when the application is finished
      _monitor.stop();
    }
  }
}

Conclusion

After completing the integration steps in this guide, Analytics should be integrated into your application. When you run it, you should see data within 5 minutes on the Analytics client dashboard. If not then please check the article on Your First Data.

See Also

Start a free trial Request a demo
Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.