Reputation: 2333
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.
Upvotes: 9
Views: 15283
Reputation: 15372
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.
Upvotes: 28