Building Your Equinox OSGi Application Server – Part 3

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.

First, let’s return to the workspace that we setup as described in the first post in this series.  Here’s what the workspace should look like after completing steps 1-4 of the first post:

p311 1024x719 Building Your Equinox OSGi Application Server   Part 3

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:

p32 1024x695 Building Your Equinox OSGi Application Server   Part 3

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).

p33 1024x695 Building Your Equinox OSGi Application Server   Part 3

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:

p34 Building Your Equinox OSGi Application Server   Part 3

And then you will see your com.mycompany.myappserverfeature listed as part of the equinox-milli.product:

p35 1024x695 Building Your Equinox OSGi Application Server   Part 3

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:

p36 Building Your Equinox OSGi Application Server   Part 3

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:

p37 Building Your Equinox OSGi Application Server   Part 3

As you can see, these bundles are in place and ready to use from within your web applications!

9 Responses to “Building Your Equinox OSGi Application Server – Part 3”

  1. Udo says:

    I have to do these steps (especially the rename job) every time I changed some Java code in one of my bundles?

  2. Scott Lewis says:

    Hello Udo.

    RE: having to do these steps after changing java code. If you wish, you can use the dynamic install/update method using p2 as described in the second post…and this makes it unnecessary to rebuild, reexport, rename. If, however, you wish to rebuild the entire app server, then yes the steps are necessary. I’m intent on opening a PDE enhancement request to create a war file directly from within the export wizard (rather than zip). If you would like to do this (open an enhancement request against PDE), please do so

  3. Scott, can you file an enhancement request for this? I believe it just requires me fixing the validation code in PDE.

    I believe right now, you aren’t allowed to change the extension from “.zip” … correct?

  4. Andrea Zoppello says:

    Hi Scott,

    Very nice series…. it help a lot to install and deploy the servlet bridge features.

    BTW the approach used in the bridge.war file downlodable from equinox wiki pages use a slightly different approach:

    1) The “simple configurator” is not used there
    2) In the bridge.war from the wiki pages the “extension bundle” is automatically generated…. why did you choose
    a different approach???

    BTW i’m also interested too to know how this works under the hood, in particular to understand
    how this happens and the detailed steps… from code development to deployments…

    Just my two cents but one of the problems with the servlet-bridge is that it use ( in my opinion ) a confusing
    packaging schema… so it’s very hard to understand which is the stuff that go in webapp, and which is the equinox
    counterpart and how to work…

    I’m writing these because i’m trying to implement a solution where i could register in my webapp an an object that let me to call osgi services installed in equinox that are not “servlets” but services that implements my interface “org.myapp.IMyInterface” for example and i’m encountering problems in developments and to setup the build and deployment environment to do that…

    Thx
    Andrea

  5. Andres says:

    Hi,

    Thanks for the tutorial. I tried to follow the steps in part 3, created my own feature and added a single plugin. Added the feature to the product, and exported the product. I can see my plugin in the plugins directory and my feature in the features directory. However, when I start tomcat I can’t see my plugin when i run “ss” from the osgi prompt. Is there anyway to get more debuging?

    Thanks a lot,

    Andres

  6. Andres says:

    Ok, why do you always have to stumble with the answer 5 minutes after posting a question that makes you look stupid? Any way, I was deploying in Tomcat, and my webapp was cached under temp. Clearing the temp directory made my bundles available.

  7. Luis Carlos Moreira da Costa says:

    Thanks for tutorial!

  8. arez says:

    Very interesting. Is there a possbility to add start level and add auto start features the way it is done in PDE?

9 responses so far

Written by . Published in Categories: Planet Eclipse