Faron - I think I fixed my problem (and without the PackageBuilder stuff) but I think I cheated :) In my BundleListener, when I find a Bundle with an .rf file I want to compile, I do this: Create an instance of a new Classloader that first delegates class loading to my BundleListener's Bundle, and if that fails, delegates to the .rf files Bundle. I pass this class loader in using a KnowledgeBuilderConfiguration.
BundleClassLoader bclassLoader = new BundleClassLoader(bundleContext.getBundle(), bundle); KnowledgeBuilderConfiguration conf = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(null, bclassLoader); KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(conf);
The Classloader looks much like yours, but each overridden call looks like:
protected Class findClass(final String name) throws ClassNotFoundException { try { Class clazz = primeBundle.loadClass(name); return clazz; } catch (ClassNotFoundException c) { if (secondBundle != null) { Class clazz2 = secondBundle.loadClass(name); return clazz2; } else { logger.info("Second is null"); throw c; } } }
Now only my bundles containing rules need to import the classes they need - my bundle containing the 'FlowManager' that wraps the call to perform does not. It allows my core Flow bundle to be totally agnostic to the data processed in it, while its clients, WorkItemHandlers and flow definition bundles only import the classes they need. Hopefully this is a lasting solution - my Drools usage isn't very complex right now. I imagine I'd have to get a little more complex if I were to use any abilities where Drools had to create instances of my domain objects at process time, but right now that is all handled by WorkItemHandlers that are registered as services from their own bundles. Mark - I'd love to help, but I'm just starting with Drools and OSGi right now, so I'm not sure I know enough yet. Mike

View this message in context: Re: RE: OSGI, classloading, and imports in KnowledgeBuilder
Sent from the drools - user mailing list archive at Nabble.com.