Creating and Compiling an OSGi plug-in project

A guide to creating and compiling an OSGi plug-in project for a custom policy.

Table of Contents

Overview

This document describes how to create and compile an OSGi Plug-in project (such as a custom policy component) using the Eclipse IDE.

Prerequisites

  • This configuration guide assumes that you’ve already installed the platform. If you need help installing the platform, refer to the Installation Guide. See Installing the Akana API Platform.
  • If you're writing policy components for the API Gateway, you'll have to create and configure a Policy Manager (PM) and Network Director (ND) container. This is described in the document Getting Started: Managing a Simple API
  • Install and configure the Eclipse IDE as described in the document Eclipse Workspace Setup.

Creating the build project

The platform ships with a number of samples that can be found in the /samples subdirectory. Included in these is a primary build project that is used for the samples. This needs to be imported into your workspace.

  1. Switch to the Java perspective, click on File, choose New, and select Java Project.
  2. Give the project the name build.
  3. Drag and drop the contents of the /samples/build directory into the root of the build project.
  4. Modify the project.properties file as follows:
    1. third.party.dir=[install_dir]/201901/lib/X.Y.Z. X.Y.Z is the version of the product installed.
    2. local.tools.dependent.lib.dir=[install_dir]/201901/lib/X.Y.Z. Same as above.
  5. Modify the build.xml file to build only the projects that are required. For example:
    ...
    <target name="clean" depends="
      complex-policy-handler-clean,
      complex-policy-console-clean
    "/>
    <target name="samples" depends="
      complex-policy-handler,
      complex-policy-console
    "/>
    ...

Creating a plug-in project

  1. Switch to the Plug-in Development perspective, click on File, choose New, and select Plug-in Project.
  2. Give the project a name, such as com.soa.examples.policy.handler.simple. In Target Platform, select the OSGi framework, and choose standard in the drop-down. Click Next.
  3. Provide or remove the qualifier in the version field and select the JavaSE-1.7 Execution Environment. Unselect Generate an Activator. Click Next.
  4. Clear the Create a plug-in using one of the templates setting, and then click Finish.

Compiling the simple policy handler example

  1. Drag and drop the contents of the /samples/com.soa.examples.policy.handler.simple directory into the root of the com.soa.examples.policy.handler.simple plug-in project created in the previous section. Since the directory already contains a MANIFEST.MF file, the values entered into #3 of the previous section will be overwritten.
  2. Build the project from top **Project ** menu and verify that there are no compilation errors.
  3. Edit the primary build file described in the previous section:
    ...
    <target name="clean" depends="
      simple-policy-handler-clean
    "/  
    <target name="samples" depends="
      simple-policy-handler
    "/  
    ...
  4. Open the Ant view and drag the primary build file into it. Double-click on the samples project to run the build script.
  5. If the build is successful, the resulting JAR file can be found in the primary build project under the /bin sub-directory. It may be hidden from view, so look on the filesystem.

Compiling the complex policy handler example

The complex policy handler is comprised of two projects, the core handler and the console project that provides a user interface for the Policy Manager.

The process for the complex handler is the same as the simple handler above:

  1. Create a new plug-in as described above. Call it com.soa.examples.policy.handler.complex.
  2. Drag and drop the contents of the /samples/com.soa.examples.policy.handler.complex directory into the root of the com.soa.examples.policy.handler.complex plug-in project created in the previous step. Since the directory already contains a MANIFEST.MF file, the values entered into #3 of the previous section will be overwritten.
  3. Build the project from top Project menu and verify that there are no compilation errors.

The console plug-in is the same:

  1. Create a new plug-in as described above. Call it com.soa.examples.console.policy.complex.
  2. Drag and drop the contents of the /samples/com.soa.examples.console.policy.complex directory into the root of the com.soa.examples.console.policy.complex plug-in project created in the previous step. Since the directory already contains a MANIFEST.MF file, the values entered into #3 of the previous section will be overwritten.

Now build both:

  1. Edit the primary build file described in the previous section:
    ...
    <target name="clean" depends="
    	complex-policy-handler-clean,
    	complex-policy-console-clean
    "/>
    <target name="samples" depends="
    	complex-policy-handler,
    	complex-policy-console
    "/>
    ...
  2. Open the Ant view and drag the primary build file into it. Double-click on the samples project to run the build script.
  3. If the build is successful, the resulting JAR files can be found in a /build/bin/ sub-directory in your Eclipse workspace root directory.