9

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.

1 Answer 1

28

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.

Sign up to request clarification or add additional context in comments.

2 Comments

So, can a bundle be used in place of a jar in a JavaEE application?
yes, it is a normal JAR. However, in a JavaEE app it will of course act as a JAR and not as a bundle.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.