Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: for the plan.

Jump to: navigation, search

Equinox/p2/Setting Start Levels

< Equinox‎ | p2

When using p2, a bundle can use a p2.inf file to provide touchpoint instructions to mark its own start level. However, if a bundle is expected to be reused in different products, then there may be conflicting requirements for what level it should actually be started at. Because of this, it is a good idea to not have the start level instructions as part of the bundle itself.

p2 has the concept of a Configuration Unit (CU). A CU is really an Installable Unit that provides configuration information . What we want is to use the p2.inf to generate a CU that provides the configuration information for a particular bundle. This CU will take the form of an Installable Unit Fragment.

By default, the generated metadata published for a product contains a default fragment which attaches to any OSGi bundle. It looks something like this:

<unit id='tooling.osgi.bundle.default' version='1.0.0' singleton='false'>
   <hostRequirements size='1'>
      <required namespace='org.eclipse.equinox.p2.eclipse.type' name='bundle' range='0.0.0' multiple='true' greedy='false'/>
   <properties size='1'>
      <property name='org.eclipse.equinox.p2.type.fragment' value='true'/>
   <provides size='1'>
      <provided namespace='org.eclipse.equinox.p2.iu' name='tooling.osgi.bundle.default' version='1.0.0'/>
   <requires size='1'>
      <required namespace='org.eclipse.equinox.p2.eclipse.type' name='bundle' range='0.0.0' multiple='true' greedy='false'/>
   <touchpoint id='null' version='0.0.0'/>
   <touchpointData size='1'>
      <instructions size='4'>
         <instruction key='install'>installBundle(bundle:${artifact})</instruction>
         <instruction key='uninstall'>uninstallBundle(bundle:${artifact})</instruction>
         <instruction key='configure'>setStartLevel(startLevel:4);</instruction>

This fragment provides instructions for 3 separate phases of a p2 install. During the install phase, the bundle must be installed into the OSGi runtime, similarly it will be uninstalled during the uninstall phase. And during the configure phase, the start level is set.

This is the kind of CU we need to generate for our bundle. PDE/Build does this automatically when exporting products. It generates a p2.inf for the .product file. When doing this manually, the p2.inf used will normally be for the feature that contains the bundle we are interested in.

The p2.inf

The p2.inf must do two things: create the CU fragment and create a requirement from the feature to the CU fragment. The requirement is needed to make sure that the fragment gets included when installing the feature. Here is an example p2.inf file that creates a fragment for the bundle org.example.bundle and sets the start level to 2 and marks the bundle to be auto-started.

#create a requirement on the fragment we are creating

#create a IU fragment named
units.0.instructions.unconfigure=org.eclipse.equinox.p2.touchpoint.eclipse.setStartLevel(startLevel:-1); \
units.0.instructions.configure=org.eclipse.equinox.p2.touchpoint.eclipse.setStartLevel(startLevel:2); \


  • $version$ will be replaced by the version of the container associated with the p2.inf, in this case the feature.
  • Here we are using fully qualified touchpoint actions like "org.eclipse.equinox.p2.touchpoint.eclipse.installBundle" to avoid confusion. This is not strictly necessary because the fragment is merged with the host IU. By default, IUs for osgi bundles have <touchpoint id='org.eclipse.equinox.p2.osgi' /> which is the type of the Eclipse touchpoint (org.eclipse.equinox.p2.touchpoint.eclipse).
  • See the Customizing Metadata page for details on the p2.inf format.
  • Currently, only one CU fragment can be attached to an IU (with the exception of translation fragments in Helios). If more than one CU fragment is available (ie, the default tooling.osgi.bundle.default and your custom fragment), then the fragment with the highest number of satisfied host requirements is used. This is why we provide 2 host requirements for our CU as compared to only one used by the default CU. If more than one CU for a given bundle has the same number of host requirements, then which CU gets chosen by p2 is unpredictable.

Back to the top