Eclipse:osgiDS

From RifidiWiki

Revision as of 23:21, 23 November 2010 by Amesycyxa (Talk | contribs)

Jump to: navigation, search

Intro

Here is a little series about osgi (including declarative services, look at part 7 and 8) [1]<br/> Getting declarative services into Eclipse RCP was quite a fight but with the help of some fellows from the #eclipse irc channel I finally managed to get 'em up and running.

Prerequisites

First we need to get some missing plugins.<br/> The declarative services spec is part of the services for OSGI R4 but it is not part of the equinox that is distributed with eclipse 3.3.<br/> So we need to go here:[2]<br/>

  • Under latest releases select 3.3.2
  • Scroll down to "Incubator" bundles
  • download org.eclipse.equinox.ds<whateverversionisthere>.jar (this is the declarative services plugin)
  • download org.eclipse.equinox.cm<whateverversionisthere>.jar (this is the OSGI admin service)
  • add the downlaoded packages to your plugins directory
  • restart eclipse

How to get it into your RCP

Now comes the tricky part.<br/> Being used to eclipse you would think adding the plugins to your run config and then firing up your app should do the trick.<br/> Nope, as you might have guessed, it's not that easy.<br/> Right now we need to get our hands dirty as we have to directly have to modify the config.ini.<br/> For a regular RCP application you don't have to touch this file and eclipse will create one for you on every run.<br/> But we actually want to use some fairly advanced features of the underlying osgi implementation and that's where we leave the default way.<br/> Open up the run configuration for your RCP app.<br/> <br/> Runconfiguration.jpg<br/> <br/> The red box shows where you have to edit.<br/> But before it starts to get messy we need a config.ini template tow ork on.<br/> Above the red box you can see a hook at default location. Go to the specified directory and pick the config.ini that is in there.<br/> Opening it up should give you something like this:<br/> <br/>

#Configuration File
#Mon May 05 23:09:09 CEST 2008
osgi.bundles=reference\:file\:/home/jochen/bin/eclipse/plugins/org.eclipse.equinox.common_3.3.0.v20070426.jar@2\:start,reference\:file\:/home/jochen
/bin/eclipse/plugins/org.eclipse.update.configurator_3.2.101.R33x_v20070810.jar@3\:start
osgi.bundles.defaultStartLevel=4
osgi.install.area=file\:/home/jochen/bin/eclipse
osgi.framework=file\:/home/jochen/bin/eclipse/plugins/org.eclipse.osgi_3.3.2.R33x_v20080105.jar
osgi.configuration.cascaded=false
osgi.splashPath=file\:/home/jochen/workspace/org.rifidi.designer.rcp

<br/> To be save I changed the default start level of the bundles to 5 and I will ad a statement to start the ds bundle at level 4.<br/> This allows ds to start before any of the other bundles get initialized.<br/> I am not 100 percent sure if this is really required but I figured it might be good to make sure when things get started.<br/> <br/>

#Configuration File
#Mon May 05 23:09:09 CEST 2008
osgi.bundles=reference\:file\:/home/jochen/bin/eclipse/plugins/org.eclipse.equinox.ds_1.0.0.v20070226.jar@4\:start,reference\:file\:/home/jochen
/bin/eclipse/plugins/org.eclipse.equinox.common_3.3.0.v20070426.jar@2\:start,reference\:file\:/home/jochen/bin/eclipse/plugins
/org.eclipse.update.configurator_3.2.101.R33x_v20070810.jar@3\:start
osgi.bundles.defaultStartLevel=5
osgi.install.area=file\:/home/jochen/bin/eclipse
osgi.framework=file\:/home/jochen/bin/eclipse/plugins/org.eclipse.osgi_3.3.2.R33x_v20080105.jar
osgi.configuration.cascaded=false
osgi.splashPath=file\:/home/jochen/workspace/org.rifidi.designer.rcp

<br/> After editing this file store it in any directory and adjust the area that within the red box.<br/> Switch from the default config.ini to a custom one and point eclipse to the location of your file.<br/> Now hit run and watch the magic unfold.

Personal tools