How to package your own p2 repository: FeaturesAndBundlesPublisher

How to package your own p2 repository: FeaturesAndBundlesPublisher

Ever wondered how you can create a p2 repository from an arbitrary bunch of pre-built Eclipse bundles and features?  OK, you might also be wondering why you would want to do that.

Let me give you a ‘real world’ situation where I badly needed to package p2 repos.  On an RCP Project that I coached last year we switched from PDE-build to Maven Tycho. In our target definition we had a folder where we happily dropped referenced third party bundles that were needed as our project evolved. Our bundles came partly from places like Orbit or from other projects in the same company. The only way I found to tell Maven to use our little collection of dependencies was to add the p2 metadata required to upgrade the folder to a real p2 repo as this can easily be registered in the POM.

So here is what you need to do:

  1.  First you need to make sure that your features and bundles are placed in the folders required by p2: ‘features’ and ‘plugins’.
  2.  Then you need to execute the headless Features and Bundles Publisher Application. The exact syntax is described here: FeaturesAndBundlesPublisher.

What comes out is a new folder containing your original bundles and features plus the generated p2 metadata stored in the files ‘artifacts.xml’ and ‘content.xml’. If you choose the -compress option, the repository files will of course be ‘artifacts.jar’ and ‘content.jar’.

And … as always: Enjoy! 🙂