felix-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Richard S. Hall" <he...@ungoverned.org>
Subject Re: Class loading issues for embedded felix within tomcat
Date Thu, 27 Dec 2012 14:08:49 GMT
On 12/27/12 07:25, itay hindy wrote:
> Hi All,
>
> I have a question about running embedded felix within tomcat.
>
> I had follow the instructions at
> http://felix.apache.org/site/apache-felix-framework-launching-and-embedding.html
>
> I manage to run felix within tomcat, however I have a problem with  class
> loaders.
>
> Here is the scenario:
> 1 - My host application needs to use the RepositoryAdmin service
> from org.apache.felix.bundlerepository-1.6.6.jar bundle
> 2 - I add the org.apache.felix.bundlerepository-1.6.6.jar to my class path
> so I can access its interfaces
> 3 - I install this bundle on my host application activator code
>       URL url =
>   this.servletContext.getResource("/WEB-INF/lib/org.apache.felix.bundlerepository-1.6.6.jar");
>      Bundle bundle = context.installBundle(url.toExternalForm());
>      bundle.start();
> 4 - I have created ServiceTracker for the RepositoryAdmin service
> 5 - In the ServiceTracker the next bold line fails with class cast exception
> public Object addingService(ServiceReference reference) {
>                  Object serviceObject = super.addingService(reference);
>              try {
>                      *repositoryAdmin = (RepositoryAdmin)serviceObject*;
> } catch (Exception e) {
> e.printStackTrace();
> }
>                  return repositoryAdmin;
>              }
>
> The reason seems to be because RepositoryAdmin interface classloader  comes
> from org.apache.catalina.loader.WebappClassLoader and the
> actual RepositoryAdminImpl  object (the *serviceObject*) is coming from
> BundleWiringImpl$BundleClassLoaderJava5

Yes, of course. The bundle doesn't have access to your outer repository 
classes and your host doesn't have access to the bundle's repository 
classes.

You will need to try to export the repository packages from your host 
app via the system bundle. Of course, this will only work if the 
repository bundle properly imports AND exports the repository packages. 
Even if it does, it is tricky and might not work if there are any "uses" 
constraint issues, but you could try. If that doesn't work, you could 
look into boot delegating the packages from your class path, but that is 
a last resort.

-> richard



>
> Any Idea?
>
> Regards,
> Itay Hindy
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Mime
View raw message