Menu

OSGi fragment bundle

What is OSGi fragment?

OSGi fragment is the java archive file or jar file or bundle, which have some classes, resource and header. The purpose of fragment to develop an extension of a bundle, which add on additional functionality and merge those functionality with host bundle at the time of host bundle is getting resolve. Before host bundle get resolved fragment appended to host. Following are the key points which we need to keep in mind while working with OSGi fragment.


  • Fragment is treated as part of the host bundles. 
  • A fragment cannot have its own class loader or bundle activator. 
  • Fragment bundle cannot override the information present in the host bundles. 
  • Both host and fragment share the same class loader from host bundle. 
  • An OSGi fragment doesn't have it life-cycle and that means we can't activate, start, stop a fragment. 
  • All classes and definition of fragment are merged with host definition when the host bundle get resolved. If the fragment dependencies cannot be resolved, the fragment does not attach to the host bundle. 
  • If any information from host and fragment conflicts then fragment will not attach and merge with host bundle. 
  • Fragments extend host bundles with resources, classes, and permitted headers. 
  • Fragments can only add new files, and does not replace or override existing files from host. 
  • OSGi fragment JAR file contains manifest file which have host bundle information. 
  • Fragment jar cannot be use independently. 
  • Fragments bundles could you attached with one or many host bundles. 


Why do we have fragments and what is the role of fragments and why we use? 


  • To provide the extra classes or additional functionality to host bundle. 
  • Add configuration files and properties.

You can create a fragment project using eclipse.

To create an OSGi fragment project in Eclipse follow the below steps:
  1. Go to File >> New >> Other >> Plug-in Development >> Fragment Project
  2. Select Fragment project and click on the next.
  3. Put a valid project name for your fragment and then click on next button.
  4. Now under the Host plun-in section, put the host bundle name in plug-in ID field.

Here is the complete step by step guide to create an OSGi fragment project using Eclipse. >> https://rashidjorvee.blogspot.com/2019/03/how-to-create-osgi-fragment-project.html

Find minimum and maximum number from a given array

This is an example code snippet to find the minimum and maximum number in a given Array using Java programming. 


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
import java.util.Scanner;

public class FindMinMaxInArray {

    public static void main(String[] args) {
        int nums[]=new int[]{3, 5, 6, 2, 4, 15, 120};
        int max = 0, min= 0;
        max = min = nums[0]; 
        for (int i = 1; i < nums.length; i++) {
            if(nums[i]>max) max = nums[i];
            if(nums[i]<min) min = nums[i];
        }
        System.out.println("Minimum number is "+min + "\nMaximum number is "+max);
       
    }
}

Output:

Minimum number is 2
Maximum number is 120

Related articles:

Convert date-time from 12 to 24 hours of format

Today we are going to see, how we can convert a 12 hour time format into 24 hour(military) time format.
For example we have date like 12 Aug, 2018 07:05 PM or 04/03/1965 02:06:45 AM or just only have time 07:15:00 AM or 08:50:25 PM which we want to convert in 24 hours format and remove the AM and PM from the date.

Here I have written a simple program which help us to understand the process and what steps do we need to perform to convert a string time into 24 hours of time format. 
Below are the code snippet.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package jorvee;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class timeFormet {

 public static void main(String[] args) throws ParseException {
  String time="07:05:45 PM";
  /*
   * This dateFormat will help you to first convert your string time into DateTime format.
   */
  DateFormat dateFormat = new SimpleDateFormat("hh:mm:ss aa");
  Date date24=dateFormat.parse(time);
  /*
   * Convert your time into 24 hours date format
   */
  DateFormat outFormat = new SimpleDateFormat( "HH:mm:ss");
  System.out.println(outFormat.format(date24));

 }
}

Output:

19:05:45