Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between OSGi bundle and normal .JAR files usage

I have recently started studying OSGi. I read that one can create bundles(which are normal java classes) and use them in another bundle by dynamically installing/uninstalling any bundle.

But I can't seem to understand the difference between a normal .JAR file usage in any java class and between usage of a bundle.

Can anybody plz help me clarify it? Thank you.

like image 551
Amrit Avatar asked Nov 28 '13 05:11

Amrit


People also ask

What is the use of OSGi bundle?

An OSGi bundle JAR file contains a JAR manifest file. This file contains metadata that enables the OSGi Framework to process the modular aspects of the bundle. Describes the version of the bundle and enables multiple versions of a bundle to be active concurrently in the same framework instance.

What are the benefits of using OSGi?

Benefits of OSGi OSGi modularity provides standard mechanisms to address the issues faced by Java EE applications. The OSGi framework provides the following benefits: Applications are portable, easier to re-engineer, and adaptable to changing requirements.

What is a OSGi bundle?

OSGi is a Java framework for developing and deploying modular software programs and libraries. Each bundle is a tightly coupled, dynamically loadable collection of classes, jars, and configuration files that explicitly declare their external dependencies (if any).

What is the difference between JAR and package?

A package is a mechanism in Java for organizing classes into namespaces. A jar is a Java ARchive, a file that aggregates multiple Java classes into one.


1 Answers

There is basically no difference. A JAR is a bundle and a bundle is a JAR, the formats are identical. However, a useful bundle requires OSGi metadata in its manifest so that an OSGi framework can manage the visibility of classes between bundles. A JAR without this metadata would only contain invisible classes, could not see any classes from other bundles, nor could it get started in any way. The Import-Package manifest header tells what packages should be made visible to the bundle, and the Export-Package defines the packages in the bundle that should be made visible to others. Other headers provide additional features.

With the traditional class path everything is shared and global, having the same class on the class path twice is not flagged anywhere, one is just ignored. The key difference with OSGi is that a JAR is now all private, adding metadata in the manifest makes it a bundle that can safely share with other bundles. OSGi makes sure violations are detected ahead of time.

like image 70
Peter Kriens Avatar answered Sep 28 '22 18:09

Peter Kriens