David,

Thanks for the reply.  I figured it had to do with Class loaders but I'm
at a loss as to how this is happening; I don't know a lot about class
loaders.

Here's some more detail on my situation: as I said we're using Felix in
an embedded fashion; we instantiate a Felix object and start it from
within a JavaFX app (we're using IntelliJ).  I suppose this is the
source of the different classloaders.  The reason I'm confused is that
we have been successfully using a ServiceTracker to get references to
our plugins without any classloading issues.  So how can I fix this?  Do
I need access Felix's classloader and use it to load the
RepositoryAdmin?  Any pointers on how to do this?

Thanks,
Tim

On 08/06/2014 03:15 AM, David Bosschaert wrote:
> Hi Tim,
>
>> java.lang.ClassCastException:
>> org.apache.felix.bundlerepository.impl.RepositoryAdminImpl cannot be
>> cast to org.apache.felix.bundlerepository.RepositoryAdmin
> This happens when the RepositoryAdmin interface is loaded from a
> different classloader than where the RepositoryAdminImpl loads it
> from.
>
> You need to check that the bundle that runs your code has an import on
> the org.apache.felix.bundlerepository package like this:
>   Import-Package: org.apache.felix.bundlerepository;version="[1.0,2)"
> and is wired to the same bundle where you get the RepositoryAdminImpl from.
>
>> By the way, is there javadoc for Felix?  I can't seem to find any.
> If you're looking for documentation on Felix, it might be best to look
> for general OSGi Framework documentation. You can find information on
> the Felix Framework in the OSGi Core R5 specs [1] or in one of the
> many books and web articles about the OSGi framework.
>
> For documentation about the Bundle Repository, it might be worth
> looking at the OSGi R5 Enterprise Specs (also at [1]). Chapter 132
> describes the OSGi Repository Service. Since version 2.0.x this is now
> also implemented by Felix OBR so using that gives you a standard API
> to work with the Repository.
>
> Cheers,
>
> David
>
> [1] http://www.osgi.org/Download/Release5
>
> On 5 August 2014 20:38, Tim McIver <[email protected]> wrote:
>> Hello,
>>
>> I'm using Apache Felix in an embedded fashion.  I'm attempting to access
>> my own bundle repository so I install and start the bundle repository
>> bundle like so:
>>
>>         // install the Felix OBR bundle
>>         Bundle obrBundle = null;
>>         try {
>>             obrBundle =
>> m_felix.getBundleContext().installBundle("file:/home/tim/workspace/clojure/lambdaprime/metascrape-ui/lib/org.apache.felix.bundlerepository-2.0.2.jar");
>>         } catch (BundleException e) {
>>             System.err.println("Error installing Felix OBR bundle.");
>>             e.printStackTrace();
>>         }
>>
>>         // start the Felix OBR bundle
>>         if (obrBundle != null) {
>>             try {
>>                 obrBundle.start();
>>             } catch (BundleException e) {
>>                 System.err.println("Could not start Felix OBR bundle.");
>>                 e.printStackTrace();
>>             }
>>         }
>>
>> I have a private method to get a RepositoryAdmin:
>>
>>     private static RepositoryAdmin getRepositoryAdmin(BundleContext ctx) {
>>         ServiceReference ref =
>> ctx.getServiceReference(RepositoryAdmin.class.getName());
>>         if (ref != null) {
>>             return (RepositoryAdmin)ctx.getService(ref);
>>         }
>>         return null;
>>     }
>>
>> But when this method is called, I get the following exception:
>>
>> java.lang.ClassCastException:
>> org.apache.felix.bundlerepository.impl.RepositoryAdminImpl cannot be
>> cast to org.apache.felix.bundlerepository.RepositoryAdmin
>>
>> I'm using felix.jar from the bin directory of of the 4.4.1 distribution
>> and using org.apache.felix.bundlerepository-2.0.2.jar for the bundle
>> repository.  Any ideas what my issue is?
>>
>> By the way, is there javadoc for Felix?  I can't seem to find any.
>>
>> Thanks,
>> Tim
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to