Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [equinox-dev] getservice throws class cast exception

Santosh,

You should not include the JAR that contains the interface in the
classpath of the two bundles. You should make it into a third bundle
and use Import-Package to depend on the interface.

When a class is defined independently by two or more classloaders, the
resulting classes are considered by the JVM to be different, even if
they have exactly the same name and are defined from the same bytes on
disk. Therefore you cannot cast an instance of one type into a field
of the other.

Regards
Neil

On 5/29/08, Santosh Akhilesh <santoshakhilesh@xxxxxxxxxx> wrote:
> Dear All,
>
>
>
> I am new to OSGI and Equinox.
>
>
>
> I have defined an interface say A, this is defined in a project and exported
> as jar
>
>
>
> Now I create Two OSGI bundles I include this jar in both the bundles.
>
>
>
> >From one bundle I implement the interface A and register the service to the
> bundle context from second bundle I try to retrieve this service from bundle
> context in the activator start function.
>
>
>
> I can see that service is retrieved but when I cast it to interface A, I get
> class cast exception
>
>
>
> Any pointer why this happens and how to correct it.
>
>
>
> Regards,
>
> Santosh Akhilesh
>
> Ph: 9845482201
>
>
>
>


Back to the top