Eclipse RCP: Setting P2 repositories (update sites) programmatically (for when p2.inf fails).
When deploying a p2 enabled RCP product, you often want to set the update sites that can be used so that they include yours. There are many resources that explain about using p2.inf to do this. However, there is an issue when trying to do this with an application that will be installed into Program Files (or any non-user-writable location) on the user’s machine. p2.inf operates by writing the repository to disk the first time that the RCP application is run. If the application is not user-writable, this will silently fail.
To set the repositories manually, you can use the same technique as the P2 property page:
import org.eclipse.equinox.internal.p2.ui.model.MetadataRepositoryElement;
import org.eclipse.equinox.internal.p2.ui.model.ElementUtils;
@SuppressWarnings("restriction")
public class P2Util {
private static String UPDATE_SITE = "http://www.example.com/update_site";
public static void setRepositories() throws InvocationTargetException {
try {
final MetadataRepositoryElement element = new MetadataRepositoryElement(null, new URI(UPDATE_SITE), true);
ElementUtils.updateRepositoryUsingElements(new MetadataRepositoryElement[] {element}, null);
} catch (URISyntaxException e) {
e.printStackTrace();
throw new InvocationTargetException(e);
}
}
}
Note that you need all of the repositories to be present in the
ElementUtils.updateRepositoryUsingElements
call; repositories not in that array will be removed.
1 Comment to “Eclipse RCP: Setting P2 repositories (update sites) programmatically (for when p2.inf fails).”
Post comment
Like us on facebook!
Recent Posts
- Building SOAP services on Google App Engine in Java: Part 1 – The Servlet
- Eclipse RCP: Setting P2 repositories (update sites) programmatically (for when p2.inf fails).
- Easily load Xtext files and objects in Eclipse plugin or RCP projects using adapters
- Howto: Mount your Android SD card under linux via wifi
- Using Log4J in Eclipse RCP (and forcing all other plugins to use it too!)


Thanks for the good writeup. It actually was a enjoyment account it.
Glance complex to more brought agreeable from you!
However, how could we keep in touch?