Java Interview Questions2 OSGI
Java Interview Questions2 OSGI
Java Interview Questions2 OSGI
OSGI
When a jarfile for a bundle is loaded , OSGi’s Framework class fisrt creates a bundle object to represent it,
and that in turn creates a classloader which is a child of an “OSGi environment classloader”.
4. Types (Hierarchy) of Java Class Loaders:
Java class loaders can be broadly classified into below categories:
Bootstrap Class Loader
Bootstrap class loader loads java’s core classes like java.lang, java.util etc. These are classes that are part of
java runtime environment. Bootstrap class loader is native implementation and so they may differ across
different JVMs.
Extensions Class Loader
JAVA_HOME/jre/lib/ext contains jar packages that are extensions of standard core java classes. Extensions
class loader loads classes from this ext folder. Using the system environment propery java.ext.dirs you can
add ‘ext’ folders and jar files to be loaded using extensions class loader.
System Class Loader
Java classes that are available in the java classpath are loaded using System class loader.
The Equinox OSGi implementation is extremely configurable. One of the most common configuration
scenarios is to have the framework automatically install and run a set of bundles when it is started. You do
this every time you run Eclipse the IDE. Here's how it works and how you can use it in your situation.
Say you have bundles B1.jar and B2.jar that you want to have installed and started when Equinox is run. As
with other OSGi implementations, you can run the framework (see above) and install and start B1 and B2
using the console. This is a manual process but you need only do it the first time you run Equinox (OSGi
frameworks remember the installed and started bundles from run to run). To do something completely
automated, create a configuration that lists B1 and B2 as bundles to be installed and started. Set up
something like
somedir/
configuration/
config.ini
org.eclipse.osgi_3.2.0.jar
B1.jar
B2.jar
Where config.ini is a Java properties file that contains the following line. Note that the osgi.bundles property
is quite powerful. See the doc for details.
osgi.bundles=B1.jar@start, B2.jar@start
eclipse.ignoreApp=true
When Equinox is started using the command line above, B1 and B2 are installed and started. If you want to
specify a different configuration, just add -configuration <location> to the command line. Notice that since
you are just running your bundles, we added a line to tell Equinox to skip trying to start an Eclipse
application. This setting is not critical but without it a scary but otherwise inoccuous message appears in
your log.