p2 in a non-eclipse system

February 19, 2009 | 2 min Read

Somebody asked me a great question the other day, can p2 be used in non-eclipse systems?  This is a great question because I think it highlights the fact that we don’t always make newcomers aware of the great power contained in the Eclipse components. Most of the Eclipse bundles are not designed simply for the IDE.  In fact, for almost all the bundles in the IDE, thought is given for how they can be generalized. The IDE is just an example of how the bundles can be used.  When developing software using the Eclipse IDE keep this mind, and you will start to see reuse opportunities everywhere! Of course – getting back to the original question regarding p2  – the answer is a resounding YES!!!

In this particular case, the user wants to use p2 in their own OSGi based application. Not only is this possible, it is remarkably easy (and you can even use the Eclipse tooling to make it easier).   For example, when you export a product,  select the  “Generate metadata repository”.  This will generate a p2 repository for your product, including Installable Units for all of your bundles and features.

Generate Metadata

 Following from Kim’s Post, say you have a repository (or even a composite repository) that holds your bundles (we call these Installable Units), you can simply use the Director Application to provision these bundles into your system.

For example:

d:\builder\eclipse.exe

-application org.eclipse.equinox.p2.director.app.application -metadataRepository https://yourrepo.com -artifactRepository https://yourrepo.com -installIU yourIU -destination d:/yourapplication -profile SDKProfile -vmArgs -Declipse.p2.data.area=d:/yourapplication/p2

In this case, you are using the director application to install yourIU (likely a bundle or feature you created) in to your application.  The profile option allows you to create a number of different profiles, each containing a different set of bundles.  Finally, the p2 data area is the place on disk that holds all the p2 information (such as profile information).

In addition to the director application, you can even reuse the p2 bundles within your OSGi based application to provide automatic updates, customizable profiles and a wide range of other provisioning operations.

What’s even more powerful, is you can use p2 for non-osgi based systems. That’s right, you can install your favorite RPMs, Debs or even MSI (Windows Installer) based applications using p2.

With today’s historic visit in Ottawa (members of the Mozilla team traveling to Ottawa to meet with Boris and Simon), here is an interesting exercise: see if we can use p2 to manage  firefox extensions.

Ian Bull

Ian Bull

Ian is an Eclipse committer and EclipseSource Distinguished Engineer with a passion for developer productivity.

He leads the J2V8 project and has served on several …