Hi Doug, Would the classloader for a specific bundle help here? It would give you access to what the bundle can see plus what it contains itself. You can obtain the bundle's classloader in two ways: 1. The easiest way is via the Bundle Wiring. If you have a bundle object, you can call bundle.adapt(BundleWiring.class) and then call BundleWiring.getClassLoader() [1] 2. If you have an actual class that you know for sure is served by the bundle, you can obtain it's classloader simply by calling Class.getClassLoader()
Cheers, David [1] http://www.osgi.org/javadoc/r5/core/org/osgi/framework/wiring/BundleWiring.html On 22 August 2014 16:48, dsjaxen <[email protected]> wrote: > Hi! > I have a couple bundles each of which includes a groovy class loader which > uses the thread context > classloader as its parent class loader. The idea is to run groovy scripts > in the class loading context > of each bundle. So bundle A which imports C, D, & E bundles would allow a > groovy script compiled > and executed in the context of bundle A to see classes from A, C, D, & E. > Groovy scripts running in bundle B would see a different set of classes > (possibly different versions of C, D, or E). > > I am using karaf 2.3.1, aries blueprint 1.0.0, & spring 3.0.7. > > I have been having issues getting the right parent classloader for the > groovy classloader. > I have seen the following: > a) Groovy classloader is created by a class created as an OSGi > service > o Using thread context classloader as the parent loader, the > groovy classloader sees all > classes exported from all bundles [not just those imported by > the bundle] > o Using class.getClassloader() as the parent loader, the groovy > classloader does not see > classes imported by the bundle. > b) Groovy classloader is created on the fly as a request is processed > o Using the thread context classloader as the parent, the groovy > classloader does not see > classes imported by the bundle. > > Using the one classloader, most things work but if multiple versions of > classes are used within the container the wrong class could be used. Also, > if the bundle is reloaded references to classes loaded > previously cause class cast exceptions. > > Is it possible to get a parent classloader for the groovy compiler that will > get me the bundle's classpath? > > Thanks in advance, > -Doug > > > > -- > View this message in context: > http://karaf.922171.n3.nabble.com/bundle-specific-classloaders-tp4034883.html > Sent from the Karaf - User mailing list archive at Nabble.com.
