by Lars Vogel

Follow me on twitter

Lars Vogel on Google+

Updating Eclipse RCP applications with p2 - Tutorial

Lars Vogel

Version 1.3

01.02.2012

Revision History
Revision 0.1 - 0.2 16.09.2008 - 12.10.2008 Lars
Vogel
Created
Revision 0.3 - 1.3 25.05.2009 - 01.02.2012 Lars
Vogel
bugfixes and updates

Eclipse p2 - Update

This tutorial describes how to setup an automatic update for Eclipse based RCP application. It uses Eclipse p2 to install new features and to add auto-update (self-update) functionality to the Eclipse application. Its based on Eclipse 3.7 and Eclipse 4.2


Table of Contents

1. Eclipse application updates with p2
1.1. Eclipse application Updates
1.2. Getting update sites
2. Pre-requisite
3. Eclipse 3.x and p2
4. Eclipse 4 and p2
5. Tutorial: Create a p2 update enable RCP app
5.1. Create plug-in and feature project
5.2. Adding the p2 UI
5.3. Update your product
6. Thank you
7. Questions and Discussion
8. Links and Literature
8.1. Eclipse p2 updater resources
8.2. vogella Resources

1. Eclipse application updates with p2

1.1. Eclipse application Updates

The Eclipse platform provides an installation and update mechanism called p2. This update mechanism allow to update Eclipse applications and to install new functionality into them.

The update and installation of functionality with p2 is based on Eclipse Features. Features basically describe a list of plug-ins and other features and represent a logical grouping of plug-ins.

1.2. Getting update sites

During the export of a product you can select if a metadata repository should be created. If you select this, a p2 update site will be created in the export directory. You find this in folder "repository".

Selection in the export wizard for the metadata repository creation

To avoid dependency problems the version number from your features in the Dependency tab of the product. You can do this via the "Properties" button.

Removal of the feature version dependency in product

This directory is your update site and could get copied to a webserver so that user could update their Eclipse application.

p2 also supports file based update sites which can be be used for testing. For local testing just copy the application to another folder and configure p2 to use this update site.

You could configure p2 at runtime with the new update site but you can also define existing update site via a p2.inf file. The content of the file points to pre-defined locations. They can be file or web based.

p2 can update complete products or individual features.

If features should be just then the should be categorized via categories. The p2 update manager groups features per default based on categories. Therefore it is usually good advice to create also a category for your feature(s) via FileNewOtherCategory Definition .

Here you can press "New Category" and create a category. The name you select will be visible in the update manager. Add the required features to this category.

2. Pre-requisite

This tutorial assumes what you have basic understanding of development for the Eclipse platform. Please see Eclipse RCP Tutorial or Eclipse Plug-in Tutorial . It also assumes that you know how to create Eclipse Feature projects. Please see Eclipse Feature and Fragment Tutorial for an introduction.

3. Eclipse 3.x and p2

Eclipse 3.7 provides a new feature "org.eclipse.equinox.p2.rcp.feature" which contains the base functionality for p2 updates for RCP applications. This makes adding p2 update functionality to your Eclipse 3.x application much easier.

This feature also allows you to re-use the existing update user interface. The user interface can be configured via a configuration file.

4. Eclipse 4 and p2

The Eclipse p2 user interface has not yet been transferred to the new Eclipse 4 programming model.

To use Eclipse p2 in an Eclipse 4 application you can use the low-level API of p2. An example for using this API is described in Headless Eclipse update .

5. Tutorial: Create a p2 update enable RCP app

5.1. Create plug-in and feature project

Create a Eclipse RCP project "de.vogella.rcp.p2.base" based on the "Eclipse RCP with a view" template.

Create an Eclipse feature project "de.vogella.rcp.p2.base.feature" which includes the plugin "de.vogella.rcp.p2.base".

Add a product configuration file (product) called "p2base.product" to your "de.vogella.rcp.p2.base" plugin. Select that this product will be based on "features" and add the features "org.eclipse.rcp", "org.eclipse.equinox.p2.rcp.feature" and "de.vogella.rcp.p2.base.feature" to your product.

Start the product from the IDE and verify that the application works correctly.

Remove the version number from your features in the Dependency tab of the product. You can do this via the "Properties" button.

Export your product and ensure that it still starts as expected.

5.2. Adding the p2 UI

Create a menu "Update" in your application and add the following pre-defined commands to it:

  • org.eclipse.equinox.p2.ui.sdk.update

  • org.eclipse.equinox.p2.ui.sdk.install

Export your product via the "Eclipse Product export wizard" on the overview tab of p2base.product. Make sure to select the "Generate metadata repository" flag on the export dialog.

Copy the application to a different folder. Start it and use the p2 commands to point to the initial export location with "repository" added to the path. This is the metadata repository.

5.3. Update your product

Make some changes in the UI, e.g. change the name of the View.

Export again your product and again include the flag "Generate Meta-data repository".

Start your product again from the copy you made earlier. Check for updates with p2. p2 should report an update of your product and perform this update.

6. Thank you

Please help me to support this article:

Flattr this

7. Questions and Discussion

Before posting questions, please see the vogella FAQ. If you have questions or find an error in this article please use the www.vogella.de Google Group. I have created a short list how to create good questions which might also help you.

8. Links and Literature

8.1. Eclipse p2 updater resources

http://wiki.eclipse.org/Equinox_p2 The Eclipse p2 update wiki

http://wiki.eclipse.org/Equinox/p2/Adding_Self-Update_to_an_RCP_Application Adding p2 update to an RCP application

8.2. vogella Resources

Eclipse RCP Training (German) Eclipse RCP Training with Lars Vogel

Android Tutorial Introduction to Android Programming

GWT Tutorial Program in Java and compile to JavaScript and HTML

Eclipse RCP Tutorial Create native applications in Java

JUnit Tutorial Test your application

Git Tutorial Put everything you have under distributed version control system