Create OSGI-Spring Project with Maven

Introduction

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.

Setup

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.

Procedure

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

directory.png

These two XML files defines your beans and OSGi Services.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

  <!-- 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" />

</beans>

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="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:osgi="http://www.springframework.org/schema/osgi"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                      http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi-1.0.xsd">

</beans>

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