Are the imported packages of fragments included in the host bundle classpath?

admin

Administrator
Staff member
I have some problems regarding OSGi fragments and
Code:
Class.forName()
. The example below illustrates my problem.

I have a third-party bundle
Code:
Foo
. I cannot modify
Code:
Foo
in any way. The bundle contains the following class:

Code:
public class Serializer {
    public String summarizeClass(String className) {
        Class<?> myClass = Class.forName(className);
        ...
    }
}

If I call this method from bundle
Code:
Bar
for
Code:
org.myPackage.MyClass
, it will fail, since
Code:
MyClass
is not on the classpath of bundle
Code:
Foo
.

Can I simply add a fragment
Code:
Foo.fragment
with a dependency to
Code:
Bar
to modify the classpath of bundle
Code:
Foo
? Or does this dependency only apply for classes within the fragment?

Long story short:
What are the semantics of
Code:
Class.forName()
in OSGi, when executed in a class of the Host bundle? Does it include:

<ul>
<li>Q: The bundle classes? A: Yes.</li>
<li>Q: The classes contained in the fragment? A: Yes. <a href="http://olegz.wordpress.com/2008/11/05/osgi-and-classforname/" rel="nofollow">Source</a></li>
<li>Q: The imported packages and the packages exported from required bundles? A: Yes.</li>
<li><strong>Q: The imported packages and the packages exported from required bundles of all fragments? A: I don't know.</strong></li>
</ul>