Home Tutorials Training Consulting Books Company Contact us






Get more...

This tutorial describes the purpose and usage of Eclipse fragment projects.

1. Using fragment projects

1.1. Definition of OSGi fragments

A fragment is an optional attachment to another plug-in. This plug-in is called the host plug-in. At runtime, the fragment is merged with its host plug-in. Therefore, for the Equinox runtime, the host plug-in and fragment are treated as a single plug-in.

Fragments are optional; the host plug-in is unaware of their presence at runtime.

The Eclipse IDE supports the creation of fragments via fragment projects. To create a fragment project select File  New  Other…​  Plug-in Development  Fragment Project.

1.2. Typical use cases for fragments

Fragments can be used to contain test classes. This way, the tests can access and test the internal API of the plug-in classes. Alternatively, tests can be contained in their own plug-in. In this case, they can only test the external API of other plug-ins.

Fragments can contribute property files for additional translations. This allows you to contribute translations for a new language without adjusting other parts of the code.

In addition, fragments can provide native code that is specific to certain operating systems. A platform filter can be used to define that the fragment is only valid for a certain operating system.

For example, the SWT user interface implementation of Eclipse uses this approach.

Fragments can also be used to contain resources like icon sets or other images. This allows you to customize your application icons via the provided fragment.

1.3. Example manifest for a fragment

The following listing shows a manifest file for a fragment that is only valid for the Windows OS. The OS is specified via the Eclipse-PlatformFilter property and the Fragment-Host makes this a fragment. If you remove Fragment-Host, the component is a regular plug-in again.

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %fragmentName
Bundle-SymbolicName: org.eclipse.ui.win32
Bundle-Version: 3.4.300.qualifier
Bundle-ClassPath: .
Bundle-Vendor: %providerName
Fragment-Host: org.eclipse.ui.ide;bundle-version="[3.2.0,4.0.0)"
Bundle-Localization: fragment-win32
Export-Package: org.eclipse.ui.internal.editorsupport.win32;x-internal:=true
Eclipse-PlatformFilter: (osgi.ws=win32)
Bundle-RequiredExecutionEnvironment: JavaSE-21
Automatic-Module-Name: org.eclipse.ui.win32

The available platform filters are:

  • Eclipse-PlatformFilter: (osgi.ws=win32)

  • Eclipse-PlatformFilter: (osgi.ws=gtk)

  • Eclipse-PlatformFilter: (osgi.ws=cocoa)