Introduction To OSGi-ed JRE

The main purpose

OSGi has became one of the best ways to govern the jar files in a number of applications ,such as the power it exhibits in eclipse .And as we all know,the Harmony runtime is a modularized one and each module , with its manifest file , is just like one bundle in the OSGi framework .So we are thinking of governing the modules in Harmony runtime in a OSGi-ed way.

Ways to meet the main purpose

Naturally, there are two ways to meet this purpose:

Finally I picked the plan B with the well known OSGi framework :Felix .And the reasons are as follows :

Problems and fixes

The difficulties ,or the main tasks ,of this project are as follows

And the fixes are

For A:

Harmony is a modularized runtime .So determine the minimum working environment is no more than choose the right module to stay with the VM .However ,although the coupling is little , it does exist . So a modification of the module is necessary ,mainly the manifest file .And as I want to remain the original structure of Harmony as possible as I can , more contents (classes ) will be included in the minimum environment other than splitting the modules apart .The final jre include the following component :

The remaining jars are governed by the OSGi framework to handle. One more thing to mention is the two classes,"java.beans.PropertyChangelinstener" , "java.beans.PropertyChangeEvent" has to be moved out of beans.jar .This is because of the coupling of beans.jar with other modules in the minimum runtime .Well the good thing is these two classes havn’t imports any other classes in the modules governed by the OSGi framework .I think we could include them in any modules lie in the minimum runtime as long as the VM could find them .

For B:

I added one extra sphere between the VM and the main class to run :org.apache.osgi.FelixStarter. , the following is done in this class

  1. Loading the configurations and Start Felix ,the OSGi framework we use
  2. Initializing the class org.apache.osgi.OsgiClassLoader ,this class will load the main class and subsequently all the classes used in the main class
  3. Transfer the arguments to the “real “ main class ,invoke the main method .

The sequence of class loading is as follows :

  1. Check the class name to determine whether it should be loaded by the parent class loader .This work is done by specifying the "org.osgi.framework.bootdelegation" property to include all the package names in the modules stays in the VM .
  2. load the classes in the bundle governed by the framework .I will examine each bundle's export and import property to search for the class name ;
  3. the classes in the application’s class path .
  4. we could not find the class and a ClassNotFoundException will be thrown .

Both the OSGi framework and the Harmony do not allow the define , imports or exports of java.* classes and packages ,so a lot of examines has been removed to facilitate our purpose .