Support free tutorials

vogella training Training Books

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. Using fragments
3. About this website
3.1. Donate to support free tutorials
3.2. Questions and discussion
3.3. License for this tutorial and its code
4. Links and Literature
4.1. Eclipse resources
4.2. vogella Resources

1. What are fragments in OSGi?

A fragment is always defined for another plug-in (host plug-in). At runtime the fragment is merged with its host project and for the runtime both projects are just one. Fragments are always optional for their host plug-in.

The Eclipse IDE supports the creation of fragments via fragment projects.

To create a fragment project select FileNewOther...Plug-in DevelopmentFragment Project.

2. Using fragments

Fragments are for example used for containing 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 for other plug-ins.

Another typical usage example for fragments are translations and native code. A new translation can be contributed to a plug-in via a fragment.

Also plug-ins uses fragments to factor out their native code parts. Via a platform filter it can be defined that a fragment can only be activate on 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 "OSGi Bundle Manifest Headers" term.

Last but not 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

3.1. Donate to support free tutorials

Please consider a contribution Support free tutorials if this article helped you. It will help to maintain our content and our Open Source activities.

3.2. Questions and discussion

Writing and updating these tutorials is a lot of work. If this free community service was helpful, you can support the cause by giving a tip as well as reporting typos and factual errors.

If you find errors in this tutorial, please notify me (see the top of the page). Please note that due to the high volume of feedback I receive, I cannot answer questions to your implementation. Ensure you have read the vogella FAQ as I don't respond to questions already answered there.

3.3. License for this tutorial and its code

This tutorial is Open Content under the CC BY-NC-SA 3.0 DE license. Source code in this tutorial is distributed under the Eclipse Public License. See the vogella License page for details on the terms of reuse.

4. Links and Literature

4.1. Eclipse resources

4.2. vogella Resources

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.