Creating a target eclipse platform and bundling non-osgi bundles on the fly

One challenge even in eclipse 3.5 is managing the target platform for your eclipse RCP.  It turns out that while many enterprise level bundles are already OSGi ready, many are not. If you want to create a target platform more easily, and have an automated build facility that does not require manual conversion of non-OSGi bundles, you need to create process to build the target platform with your 3rd party bundles.

The idea is very similar to what is described in this blog http://springosgi.googlepages.com/ where a target platform is built for a spring dm (spring dynamic modules) environment. Follow the instructions at http://springosgi.googlepages.com/ch01.html carefully. But the question is, if you have non-OSGi bundles, what do you do? Can you automate the process?

Lets assume that you have a bundle that should be in the target but is not OSGi. I’ll use miglayout-3.7-swt.jar as an example.

Prepare Your Eclipse Environment

Install m2eclipse, http://docs.codehaus.org/display/M2ECLIPSE/Home.

This will implement the maven functionality to manage dependencies. This should have be installed if you followed the instructions on the blog.

Enhance Your pom.xml

First, add  the following repository to your pom file:

   1: <repository>
   2:     <id>com.springsource.repository.bundles.milestone</id>
   3:     <name>SpringSource Enterprise Bundle Repository</name>
   4:     <url>http://repository.springsource.com/maven/bundles/mileston</url>
   5: </repository>

Then add the following plugin to your pom.xml:



   1: <plugin>
   2:                 <groupId>com.springsource.bundlor</groupId>
   3:                 <artifactId>com.springsource.bundlor.maven</artifactId>
   4:                 <version>1.0.0.M2</version>
   5:                 <executions>
   6:  
   7: ...multiple executions to transform the bundles using bundlor...
   8:  
   9:                 <executions>
  10:  
  11: </plugin

And within that plugin definition, you can have multiple execution entries:



   1: <execution>
   2:                         <id>miglayout</id>
   3:                         <phase>package</phase>
   4:                         <goals>
   5:                             <goal>transform</goal>
   6:                         </goals>
   7:                         <configuration>
   8:                             <failOnWarnings>false</failOnWarnings>
   9:                             <removeNullHeaders>true</removeNullHeaders>
  10:                             <bundlePath>jars/miglayout-3.7-swt.jar</bundlePath>
  11:                             <packagings><packaging>pom</packaging></packagings>
  12:                             <outputBundle>target/${project.artifactId}.miglayout.3.7.swt.jar</outputBundle>
  13:                             <manifestTemplatePath>${basedir}/template.mf</manifestTemplatePath>
  14:                             <manifestHeaders><![CDATA[Bundle-Name: Miginfocom SWT
  15: Built-By: org.you
  16: Bundle-SymbolicName: net.miginfocom.swt
  17: Bundle-Version: 3.7.0
  18: ]]></manifestHeaders>
  19:                         </configuration>
  20:                     </execution>

Here we have assumed that the folder called jars holds the non-OSGi jars. Maven could also download those to the jars directory as well but you could just copy them to that special directory.


You’ll need a template.mf as well and it will find the default although I set it explicitly in the pom.xml. Don’t forget that the template is extremely sensitive to spaces after the colons (:), you need to have a space.



   1: Excluded-Exports: 
   2:  *.internal*
   3: Import-Template: 
   4:  *;resolution:=optional
   5: Unversioned-Imports:  
   6:  *

Run Maven Packaging


The use the right mouse button context menu to RunAs: Maven Packaging. This builds your target definition. Don’t forget to reload the target platform definition in Windows>Preferences>PDE>Target Platform to ensure that it has all the plugins that were downloaded or were created. You can also stick in other headers inside the POM for the manifest, such as Eclipse-BuddyPolicy: Registered.

Popular posts from this blog

React, Redux, Recompose and some simple steps to remove "some" boilerplate and improve reuse

graphql (facebook), falcor (netflix) and odata and ...

cats/cats-effect and webservices function composition