In part 2 of this blog series, I described how to use Equinox p2 to install a new feature into a running Equinox application server. Rather than do this install at runtime via the OSGi console, many times it’s desirable to add bundles to an application server statically at build time rather than at runtime. For example, this is usually the case when adding libraries for your web application to use. These libraries are sometimes created by others and sometimes created by you.
This post will go through a simple example of how to add your own bundles to your Equinox application at build time.
To add sets of bundles to the target application server, we create a new feature for grouping the bundles. A feature project is created through the new project wizard via menu selections New Project->Other…->Plugin Development->Feature Project. I’ve created a new empty feature called com.mycompany.myappserverfeature, but it can be called anything you like:
Then choose the Plug-ins (otherwise known as bundles) tab in the feature editor and you can add bundles to be included in your new feature. The bundles that appear in the dialog when selecting Add… will include all the bundles in your workspace, as well as all bundles currently included in your target platform. For a description of how to add to your target platform, and an explanation of what you can do with the target platform since Eclipse 3.5 please see the Improved Target Platform Management blog post.
I’ve also added some bundles in my target platform that support doing ECF remote services with the r-OSGi provider. This enables support for remote OSGi services between application servers (i.e., having one server call a remote OSGi service exposed by another server).
After adding the bundles you wish to include, save the changes to your feature and then add your new feature to the equinox-milli.product. Features can be added to the equinox-milli.product on the Dependencies tab of the equinox-milli.product editor.
Here’s the Feature Selection dialog that appears when you select Add… on the Dependencies tab:
And then you will see your com.mycompany.myappserverfeature listed as part of the equinox-milli.product:
Save the changes to the equinox-milli.product and then you can go to product editor Overview tab, select the Eclipse Product export wizard (in lower right of Overview tab) to display the export wizard dialog:
You can now click Finish and do exactly the same things as described in steps 6, 7, 8, 9 in the original post to create a zip file (e.g., named myappserver.zip), rename it to myappserver.war and then hot deploy the new war file to your servlet container of choice to run it.
Once running, at the osgi> prompt you can convince yourself that the added bundles are now present in your application server by typing ss and looking for the bundles added by your feature in the resulting list:
As you can see, these bundles are in place and ready to use from within your web applications!
Latest posts by Scott Lewis (see all)
- Building Your Equinox OSGi Application Server – Part 3 - August 20, 2009
- Building Your Equinox OSGi Application Server – Part 2 - August 17, 2009
- Building Your Equinox OSGi Application Server – Part 1 - August 15, 2009