NOW Hiring

Quick links

Eclipse Fragment Projects - Tutorial

Lars Vogel

Version 2.3


Eclipse Feature Project

This tutorial describes the purpose and usage of Eclipse fragment projects

Table of Contents

1. What are fragments in OSGi?
2. Typical use cases for fragments
3. About this website
4. Links and Literature
4.1. Eclipse resources
4.2. vogella GmbH training and consulting support

1. What are fragments in OSGi?

A fragment is an optional attachment to another plug-in. This other plug-in is called the host plug-in. At runtime the fragment is merged with its host plug-in and for the runtime both projects are just one. Fragments are always optional for their host plug-in and the host plug-in doesn't even know that it exists.

The Eclipse IDE supports the creation of fragments via fragment projects. To create a fragment project select FileNewOther...Plug-in DevelopmentFragment Project.

2. Typical use cases for fragments

Fragments can be used to contain test classes. This way the tests can access the host plug-in classes, even if the host plug-in does not define them as external API. Sometimes tests are also contained in normal plug-ins, in this case they can only test the external API of other plug-ins.

Fragments can also be used to contribute property files for additional translations. This allows contributing support for a new language without the need to adjust any other part of the code.

In addition, fragments can also supply native code which is specific to a certain system environment. A platform filter can be used to define a fragment as valid for a certain platform. The Eclipse user interface library SWT uses this approach. More information on the platform filter can be found in the Eclipse help system if you search for the following term: "OSGi Bundle Manifest Headers".

Last but not the least, fragments can be used to contain resources like icon sets or other images. This allows you to customize your application icons via the provided fragment.

3. About this website

4. Links and Literature

4.1. Eclipse resources

4.2. vogella GmbH training and consulting support

The vogella company provides comprehensive training and education services from experts in the areas of Eclipse RCP, Android, Git, Java, Gradle and Spring. We offer both public and inhouse training. Whichever course you decide to take, you are guaranteed to experience what many before you refer to as “The best IT class I have ever attended”. The vogella company offers expert consulting services, development support and coaching. Our customers range from Fortune 100 corporations to individual developers.