Quantcast
Viewing latest article 2
Browse Latest Browse All 5

Spring Dynamic Modules for OSGi(tm) Service Platforms

Image may be NSFW.
Clik here to view.

The Spring Dynamic Modules for OSGi(tm) Service Platforms project makes it easy to build Spring applications that run in an OSGi framework. A Spring application written in this way provides better separation of modules, the ability to dynamically add, remove, and update modules in a running system, the ability to deploy multiple versions of a module simultaneously (and have clients automatically bind to the appropriate one), and a dynamic service model.

OSGi is a registered trademark of the OSGi Alliance. Project name is used pending approval from the OSGi Alliance.

How to create a Spring bundle project in maven (and eclipse…)

The Spring-OSGi project supplies a maven archetype that will create a Spring bundle project for you all set up and ready to go.

To create a new project simply type the following:

mvn archetype:create   \
   -DarchetypeGroupId=org.springframework.osgi   \
   -DarchetypeArtifactId=spring-osgi-bundle-archetype   \
   -DarchetypeVersion=1.0   \
   -DgroupId=<your-project-groupId>  \
   -DartifactId=<your-project-artifactId> \
   -Dversion=<your-project-version>

The result of this is a maven project that defines a simple bean, configures it using src/main/resources/META-INF/spring/bundle-context.xml and src/main/resources/META-INF/spring/bundle-context-osgi.xml, and provides unit and (out of container) integration tests. The project is packaged as an OSGi bundle.

There project does not contain a META-INF manifest yet – to generate one invoke the following command:

mvn package
mvn org.apache.felix:maven-bundle-plugin:manifest

You should now see the MANIFEST under target/classes/META-INF/ folder (the upcoming 1.0.1 version will properly generate this folder under META-INF).

Note: if you haven’t already downloaded and installed the spring-osgi artifacts (by running ‘mvn install’ on the spring-osgi tree) you’ll need to add an additional parameter to the above command: -DremoteRepositories=http://s3.amazonaws.com/maven.springframework.org/milestone. If this parameter does not work for you first time, see the additional instructions here.

Second Note: Snapshots version are available from: -DremoteRepositories=http://s3.amazonaws.com/maven.springframework.org/snapshot

Simply ‘cd’ into your newly created project directory and type ‘mvn install’ and you are good to go!

Generated Project features at-a-glance:

  • Packaged as an OSGi bundle
  • src/main/resources/META-INF/MANIFEST.MF for OSGi bundle automatically generated (may need some hand-editing for bundle name and Import-Package entries).
  • Simple bean interface and implementation defined. Interface and implementation types are in different packages, only the interface package is exported by the bundle.
  • src/main/resources/META-INF/spring/bundle-context.xml is a spring configuration file that defines the simple bean.
  • src/main/resources/META-INF/spring/bundle-context-osgi.xml is a spring configuration file ready for you to add bean definitions from the osgi namespace (services, references etc.).
  • BeanImplTest case defined to unit test the simple bean
  • BeanIntegrationTest defined to fire up the non-osgi portions of the application context configuration and test outside of OSGi
  • .project, .classpath, and build.properties files created to enable use of this project directly inside eclipse as a PDE plugin project

Using the archetype from within Eclipse

You can make it really easy to create a new Spring-OSGi bundle project from within eclipse by defining a new “External Tools” launch configuration. Open the “External Tools” configuration dialog, select the “Program” category and click “new”. Now you can define a new launch configuration as shown below:

The “${string_prompt}” entries cause eclipse to pop up a dialog asking you for a value when you run tool. You can also change the working directory to be something other than the workspace location (or even a ${folder_prompt} prompt if you like). This is the directory in which your new project will be created.

Now the creation of a new Spring-OSGi bundle project is as easy as:

Note: the generated eclipse project depends on a number of the spring-osgi bundle projects that it expects to find installed in your workspace. See the instructions here for setting these additional projects up (one-time task).

[http://www.springframework.org/node/361]
[http://www.springframework.org/osgi]

Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.

Viewing latest article 2
Browse Latest Browse All 5

Trending Articles