Create OSGI-Spring Project with Maven


This document is for developers who knows Java, but not familiar with new technologies such as Spring or OSGi.

Your First Spring-OSGi Project

In this section, you will learn how to create simple Spring + OSGi project with Maven.


For this tutorial, you need to install the following software:

Installation of Maven is simple. All you have to do is just download, unzip, and set path to the maven directory.


mvn clean install pax:provision

Inside Your Bundle

Let's look into the code.

kono$ cd org.cytoscape.sample
kono$ ls -l
total 16
-rw-r--r--   1 kono  kono   201 Mar 11 17:36 osgi.bnd
-rw-r--r--   1 kono  kono  2656 Mar 11 17:36 pom.xml
drwxr-xr-x   4 kono  kono   136 Mar 11 17:36 src
drwxr-xr-x   6 kono  kono   204 Mar 11 17:54 target

This is the basic directory structure of Spring-OSGi project created by maven. In the following directory, you can see two XML files


These two XML files defines your beans and OSGi Services.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""

  <!-- regular spring configuration file defining the beans for this
       bundle. We've kept the osgi definitions in a separate 
       configuration file so that this file can easily be used
       for integration testing outside of an OSGi environment -->

  <bean name="myExampleBean" class="org.cytoscape.sample.internal.ExampleBeanImpl" />


This is the file to define your beans. In this example, only one bean named myExampleBean is defined. This entry creates an instance of org.cytoscape.sample.internal.ExampleBeanImpl and that's all Spring does in this example.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""


By default, nothing defined in this file. We can tell Spring DM which beans should be exported as OSGi services by writing settings in this file.

Summary So Far

(to be continued...)

Outdated_Cytoscape_3.0/Developer/CreateProject (last edited 2011-02-24 15:37:11 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