How to Build an OSGi-Based Cytoscape 3 Plugin on Eclipse



This tutorial is a step-by-step instruction for creating Cytoscape 3 plugin based on OSGi framework. By following this tutorial, you can create a new plugin for Cytoscape 3.


In an OSGi system, everything is a plugin. This means, Cytoscape 3 running on OSGi framework is a collection of plugins called bundle and developing a plugin for Cytoscape 3 is equivalent to developing OSGi bundles.

MLC: I'm finding the use of the term 'plugin' really confusing because there appears to be at least four different types of 'plugins'. There are the older (C2.6) Cytoscape plugins, Maven plugins, Eclipse plugins (that use OSGI framework?), and OSGi plugins. Several of these are being referenced in various ways in this document. How can we clearly differentiate each type of plugin?

The main difference between Cytoscape 2.x plugin and 3.x plugin is that you do not have to implement CytoscapePlugin interface in Cytoscape 3. Instead, you need to build your plugin jar file with metadata for OSGi. However, this process will be handled by Eclipse and other tools and you do not have to create metadata manually.


To understand each steps in this document, it is better to understand following before building your plugin:


The following tools should be installed on your machine before starting this tutorial:

Eclipse Plugins

Goal of This Tutorial

There are lots of ways to organize your plugin project directory, but in this tutorial, for simplicity, we will use the following directory structure:

Other directories will be generated automatically. Your workspace will look like the following:

In the example above, samplePluginA is the name of plugin project and plugin1 is the name of plugin bundle.

MLC: I'm very confused with this structure. Why is the name of the plugin project different then the bundle? Why wouldn't be something like samplePluginA and samplePluginABundle? Is it better to place both the bundle and the plugin under a common superdirectory or separate them? If everything was under a common superdirectory, then it would be clear that samplePluginA is related to plugin1. Is there ever a case were you would have multiple bundles under the same plugin project? I would like a more general discussion of how we should name and place our new plugin (or name and place the migration of an existing C2.6 plugin to C3.0).

MLC: The naming used in this example should be changed to be consistent with the rest of this document (e.g., c3plugin and sampleBundle).


Since this project depends on Cytoscape 3 core, you need to know how to build and run Cytoscape 3 on Eclipse. Please read this tutorial first.


Part 1: Create New Plugin Project

  1. Start Eclipse. For simplicity, I recommend to use fresh and empty workspace without any other projects.
  2. Select Run > Run Configurations...

  3. Right click Maven Build and create new configuration

  4. Press Variables... and select workspace_loc as the destination directory for the new plugin project. However, the location is up to you. You can select any directory.


  5. Press Select... and use the tree browser to expand pax and then choose create-project as the goal.

  6. Press Add and set artifactId and groupId. Usually, groupId is based on your organization's URL. This is because once you publish your plugin in the Maven repository, the string groupId+artifactId must be unique to locate your project


    MLC: Wouldn't the groupId be in java package form, so that it would be 'org.cytoscape' versus ''?

    MLC: You need to make sure artifactId is a different name than your existing Eclipse projects, othwerwise you will run into conficts later. This is more of an issue when migrating C2.6 plugins to C3.

  7. Press Apply and Run.

  8. At this point, there is no new project in your workspace. This is normal since the process above only creates Maven project, not an Eclipse project.
  9. Open File > Import window and expand 'General' in the tree browser, then select Maven Projects


  10. Choose the 'Root Directory:' where your project is located and select all the checkboxes for your project.


    MLC: Sometimes, when I perform this on windows, all the checkboxes below the top-level pom.xml file are grayed out.

  11. Click the Finish button.

Part 2: Create Plugin Bundle

Next, you need to create an actual OSGi bundle of your plugin. You can create multiple bundles for a plugin, but in this tutorial, your plugin consists of one bundle.

  1. Select Run > Run Configurations...

  2. Right click Maven Build and create new configuration

  3. Browse Workspace and select your project root directory

  4. Set the goal to create-bundle under the pax entry in the tree browser.

  5. Add two parameters for the new plugin. package will be the root package name of this bundle, and bundleName will be the name of your new plugin. Also, add junit parameter to automatically generate test case template. The value should be the version of JUnit you want to use.


    MLC: You need to make sure bundleName is a different name than any of your existing Eclipse projects, othwerwise you will run into conficts later. This is more of an issue when migrating C2.6 plugins to C3.

  6. Press Apply and Run

  7. Next, you need to add OSGi project nature to your workspace. Select Run > Run Configurations...

  8. Right click Maven Build and create new configuration

  9. Browse Workspace and select your project root directory

  10. Goal should be pax:eclipse


  11. Press Apply and Run

  12. Import the generated bundle into your workspace. It is same as part 1. Now your workspace looks like the following:


    The samplebundle folder is the actual project you are going to write your plugin.

    MLC: Why do we have to have two eclipse projects--an OSGi plugin project and a bundle plugin? With our Cytoscape 2.6 versions of plugins, we then have three different Ecplipse projects per plugin. It sure would be nice to just have one C3 project.

    MLC: What is the purpose of the mysterious "adding OSGi project nature"?

    MLC: Do the names generated for the various settings projects in Eclipse (e.g., compiled-bundle-settings, provision, shared-bundle-settings, wrapper-bundle-settings) present a problem when you have several plugins? For example, are these settings files updated for each plugin or just represent the last plugin C3 plugin you created, or something else?

OSGi Project Directory Structure

In the samplebundle directory, you may see some new files you are not familier with.

Part 3: Add Cytoscape Application Dependency

To run your plugin with Cytoscape 3 core distribution, you need to add all of its bundles to plugin pom.xml file.

Part 4: Adding Your Plugin to the Maven Repository

You now need to add your plugin to the Maven repository so it can be found and loaded when you run Cytoscape. To do this from Eclipse, you need to make another run configuration that installs the plugin:

  1. Select Run > Run Configurations...

  2. Right click Maven Build and create new configuration.

  3. Pick an approriate name for the configuration (e.g., Add Plugin to Repository), pick your Base directory to be your plugin root(e.g., ${workspace_loc:/c3plugin}), and enter install in the Goals: box.

  4. Click the Apply and Run buttons. The Eclipse console output should specify that the build was successful. After the build, your plugin will be in the Maven repository and ready to run.

    MLC: We need a screenshot of the configuration. I can't make a screenshot that matches the look and feel and OS of the other screenshots.

Part 5: Run Template Project with Cytoscape

  1. Create new Maven Run target. Base directory is your plugin root (see the screenshot below)


    MLC: For the goal, is the user suppose to type 'pax:provision' or select the provision goal under pax using the tree browser? If the goal is selected, then the real goal would be org.ops4j:maven-pax-plugin:1.3:provision.

  2. Apply and Run. You can see Cytoscape 3 and your new plugin are running together on the same OSGi framework.


    If you type services, you can see example OSGi service which is defined in the template code is running.


  3. Quit Cytoscape

Part 6: Edit Template Code

Now you are ready to write your own code. Let's add a very simple code to the template.

  1. Open samplebundle > src/main/java > org.cytoscape.sample.internal >

  2. Edit the following method and save it

   1         public void start(BundleContext bc) throws Exception {
   2                 System.out.println("STARTING org.cytoscape.sample");
   4                 Dictionary props = new Properties();
   5                 // add specific service properties here...
   7                 System.out.println("REGISTER org.cytoscape.sample.ExampleService");
   9                 // Register our example service implementation in the OSGi service
  10                 // registry
  11                 bc.registerService(ExampleService.class.getName(),
  12                                 new ExampleServiceImpl(), props);
  14                 JOptionPane.showMessageDialog(null, "Hello Cytoscape 3!",
  15                                 "Plugin Initialized", JOptionPane.INFORMATION_MESSAGE);
  16         }
  1. Right-click the root dir of the project (in this example, it is c3plugin) and execute Run As > Maven install

Part 7: Debug your Plugin

  1. Add a brakepoint to your plugin code. As an example, add it in the new line you have just added to the template


  2. Create a new debug configuration. Select Run > Debug Configurations and create new OSGi configuration.

  3. In the Bundles tab, uncheck all bundles. Then select Felix 1.0.4 via PAX Runner for Framework


  4. In the Arguments tab, add following as VM arguments



  5. In the PAX Cursor tab, press Add POM and select deploy-pom.xml under PLUGIN_PROJECT_ROOT/runner directory where PLUGIN_PROJECT_ROOT is your plugin project's root directory. You need to select Any File to make deploy-pom.xml be displayed.

  6. Set update to yes


  7. Apply and Debug. PAX Runner executes Cytoscape 3 and your plugin. It will stop at the break point.


  8. Press resume button and continue. Eventually, you will see the following dialog on the Cytoscape Desktop:


Use Spring Dynamic Modules for Your Plugin

If you want to use OSGi service mechanism, using Spring Framework is a good alternative to use OSGi-dependent API directly. In this section, you will learn how to create Spring-Powered bundles for your plugins.

Install Spring IDE

There is an Eclipse plugin for editing Spring configuration files. You can use this for your Spring-OSGi Cytoscape plugin project.

Note: although this program is called Spring IDE, it is not an independent application. It is just a regular Eclipse plugin.

You can follow this instruction to install it:

Create Spring-Powered Bundle

There are only two differences between OSGi-dependent plugins and Spring-DM plugins:

  1. Add one more parameter when you create bundle. When you create a plugin bundle, add spring as an extra parameter. Then PAX Construct automatically generates template bundle project ready for writing Spring-DM code. spring1.png spring12.png

  2. Set PAX Cursor profile to spring. All you have to do is just check the spring checkbox on the Pax Cursor tab. spring2.png

That's it. While your plugin is running with PAX Cursor, type ps in the console. You can see Spring-DM infrastructure bundles are running with Cytoscape 3.

More advanced tutorial including how to write Spring-DM setting files will be available soon.

Outdated_Cytoscape_3.0/Eclipse/PluginDevelopment (last edited 2011-02-24 15:36:04 by PietMolenaar)

Funding for Cytoscape is provided by a federal grant from the U.S. National Institute of General Medical Sciences (NIGMS) of the Na tional Institutes of Health (NIH) under award number GM070743-01. Corporate funding is provided through a contract from Unilever PLC.

MoinMoin Appliance - Powered by TurnKey Linux