Eclipse RCP and P2 Headless Update on Startup

This post is neither a tutorial on how to build Eclipse RCP applications nor how to create Eclipse RCP plugins and features, it is a tutorial on how to make and configure an Eclipse RCP application check for updates on startup.

Context

  • Eclipse 3.7 platform
  • Java 6

Basic example project layout

The plugin project

Add the following dependencies to your plugin

  • org.eclipse.equinox.p2.core
  • org.eclipse.equinox.p2.operations
  • org.eclipse.equinox.p2.repository
  • org.eclipse.equinox.p2.metadata

plugin dependencies

Copy the following classes to your plugin src folder

Override the postWindowOpen method of your ApplicationWorkbenchWindowAdvisor class and add in the following code

@Override
public void postWindowOpen() {
    BundleContext bundleContext = Activator.getDefault().getBundle().getBundleContext();
    ServiceReference<IProvisioningAgent> serviceReference =   bundleContext.getServiceReference(IProvisioningAgent.class);
    IProvisioningAgent agent = bundleContext.getService(serviceReference);
    if (agent == null) {
        System.out.println(">> no agent loaded!");
        return;
    }
    // Adding the repositories to explore
    if (! P2Util.addRepository(agent, "http://localhost/p2/repository")) {
        System.out.println(">> could no add repostory!");
        return;
    }
    // scheduling job for updates
    UpdateJob updateJob = new UpdateJob(agent);
    updateJob.schedule();
}

The feature project

Declare your startup plugin into your feature and add in the following plugins

  • com.ichir.projects.p2update.plugin1 (the plugin we’ve created earlier)
  • org.eclipse.core.net
  • org.eclipse.equinox.ds
  • org.eclipse.equinox.p2.core
  • org.eclipse.equinox.p2.director
  • org.eclipse.equinox.p2.engine
  • org.eclipse.equinox.p2.metadata
  • org.eclipse.equinox.p2.metadata.repository
  • org.eclipse.equinox.p2.publisher
  • org.eclipse.equinox.p2.publisher.eclipse
  • org.eclipse.equinox.p2.repository
  • org.eclipse.equinox.p2.repository.tools
  • org.eclipse.equinox.simpleconfigurator
  • org.eclipse.osgi
  • org.eclipse.ui.forms
  • org.eclipse.swt.win32.win32.x86

The org.eclipse.swt.win32.win32.x86 plugin depends of course on your platform.

feature dependencies

The .product configuration file

Make your product configuration depends on feature and add in the following features

  • org.eclipse.rcp
  • org.eclipse.equinox.p2.rcp.feature
  • com.ichir.projects.p2update.feature1 (the feature we’ve created earlier)

P2 Product dependencies

Specify the following starting levels in your product file

Product start configuration

Versioning

When building Eclipse RCP with auto update features, versioning plugins, features and product is a major part! Each time you want to publish an update on a plugin, its version must be augmented, and so its containing feature and the product file. For simplicity, we can add the “.qualifier” to all our versions to automatically augment the version numbers each build is made.

Exporting application, generating the P2 repository and testing

  1. From the .product file, export the application with caution to check “Generate metadata repository” option. This will generate the executable application aside with a repository folder. Just ignore that repository.
  2. Make any modification to your UI and re-export the application to another folder. This time ignore the generated application and copy the generated repository to your HTTP web server (remember that we added “http://localhost/p2/repository&#8221; as an update repository in ApplicationWorkbenchWindowAdvisor)
  3. Once your application restarted, you should be prompted for an update!

That’s done! Enjoy!

References
To complete

Downloads
To complete

Advertisements

8 thoughts on “Eclipse RCP and P2 Headless Update on Startup”

  1. I appreciate your tutorial. It helped me implementing an automatic update for a linux client. But going through the same steps the same application (using a different feature and product, of course) refuses to run under Win7. In my case the application finds a new version and downloads the new files. But after performing a restart the application uses the old version and tries to download the same content again. Do you have any idea what’s going on?

    1. Thank you.
      1. Where did you install your application? Do your application have write rights on that folder. I have developed an application with auto-update features on Win 7, but we had opened all the rights on the install folder (actually it was on C:\ProgramData)
      2. Do you paid attention to correctly version all your plugins you want to update (or added .qualifier to all your plugins), and for the features too (if it is feature based application)

      After downloading the plugins, does the update process pops up a dialog about jar signatures?

      1. Thank you for you quick response!
        Yes, I am using Win7 and the folder access rights should be fine. I have tried versioning by using .qualifier and explicit version. Both failed. And yes, a dialog regarding the jar signatures pops up. Is that OK? I would highly appreciate if you could provide your complete Eclipse product. This would help finding the reason for that problem.

  2. Hi,
    I finally found the root cause of the problem: If the product is bundled with a JRE it seems that the application tries to replace the JRE when an update operation is running. But this fails under Windows 7. As soon as the update doesn’t contain the JRE it works perfectly.

    Thank you again for that good tutorial and your help!

  3. I follow the tutorial and it work very well. Thank you very much. It’s work on my conputer which is not bihind a http proxy but I install my eclipse RCP application on an other network which is bihind a proxy and have a “non route to host” error. How can I configure the proxy network. Thank you.

    1. I addressed a similar issue on a previous project; what I can suggest to you first is to have a look at that post on how to handle proxies. I will also advise you to have a look at the ProxySelector : the idea behind is to set a ProxySelector as the application default proxy selector on application startup, before any P2 update mechanism start.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s