| Summary: | OSGi: KieContainer cannot find KieModule defined in the same OSGi bundle | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Product: | [Retired] JBoss BRMS Platform 6 | Reporter: | Marek Winkler <mwinkler> | ||||||
| Component: | BRE | Assignee: | Mario Fusco <mfusco> | ||||||
| Status: | CLOSED CURRENTRELEASE | QA Contact: | Marek Winkler <mwinkler> | ||||||
| Severity: | high | Docs Contact: | |||||||
| Priority: | high | ||||||||
| Version: | 6.0.0 | CC: | ahoness, etirelli | ||||||
| Target Milestone: | ER1 | ||||||||
| Target Release: | 6.0.1 | ||||||||
| Hardware: | Unspecified | ||||||||
| OS: | Unspecified | ||||||||
| Whiteboard: | |||||||||
| Fixed In Version: | Doc Type: | Bug Fix | |||||||
| Doc Text: | Story Points: | --- | |||||||
| Clone Of: | Environment: | ||||||||
| Last Closed: | 2014-08-06 19:58:45 UTC | Type: | Bug | ||||||
| Regression: | --- | Mount Type: | --- | ||||||
| Documentation: | --- | CRM: | |||||||
| Verified Versions: | Category: | --- | |||||||
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |||||||
| Cloudforms Team: | --- | Target Upstream Version: | |||||||
| Attachments: |
|
||||||||
Created attachment 837643 [details]
Maven project with reproducer
Fixed by https://github.com/droolsjbpm/droolsjbpm-integration/commit/d44b21b7b Be aware that the pom.xml file of the attached test case is wrong since it doesn't add the resource folder to the jar when packaging the project. To fix this problem is enough to add the following to the pom.xml itself: <resource> <directory>${project.basedir}/src/main/resources</directory> <filtering>false</filtering> </resource> I tested that the provided solution works with fuse, but I also found that it doesn't with karaf. However to make it work also with karaf it is sufficient to add the following statement Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); before creating the KieClasspathContainer in the project's code. We are discussing if this is enough or we will need a more structural solution. We decided that relying on the Thread context ClassLoader was too fragile so I added the possibility to specify your custom ClassLoader when creating a new KieContainer from the classpath. This means that know it is possible to create the KieBase used in the attached example just doing: KieBase kbase = ks.newKieClasspathContainer(getClass().getClassLoader()).getKieBase(); I implemented this feature here https://github.com/droolsjbpm/droolsjbpm-knowledge/commit/1cf6aa7ad and https://github.com/droolsjbpm/drools/commit/cc0cbd707 Verified on BRMS 6.0.1 ER1. |
Created attachment 837642 [details] Stacktrace from <jboss_esb>/data/log/fuse.log Description of problem: When an OSGi bundle defines some kmodule (by containing META-INF/kmodule.xml), and I try to create a KieClasspathContainer, it does not see the KieModule defined in kmodule.xml. It does not matter if I use KieServices.newKieClasspathContainer() or KieServices.newKieContainer(ReleaseId). It also does not matter if I use default KieBase, or attempt to get one by specifying its name. See the attached maven project with reproducer for more details. Version-Release number of selected component (if applicable): BRMS 6.0.0 ER5 Drools 6.0.0-SNAPSHOT JBoss Fuse 6.0.0 Steps to Reproduce: 1. Build attached maven project (mvn clean install) - you might want to adjust the drools.version property in the pom. If you want to build with product binaries, the build requires VPN. 2. Run JBoss Fuse (<jboss_fuse_dir>/bin/fuse) 3. Execute the following commands: features:addurl mvn:org.kie.examples/kie-osgi-sample/1.0.0-SNAPSHOT/xml/features features:install my-kie-osgi-sample Actual results: Bundle activation fails with the message: Error executing command: Could not start bundle mvn:org.kie.examples/kie-osgi-sample/1.0.0-SNAPSHOT in feature(s) my-kie-osgi-sample-6.0.0-redhat-6: Activator start error in bundle kie-osgi-sample [197]. The log file contains (see the attachment for the whole stacktrace): java.lang.RuntimeException: Cannot find a defualt KieBase at org.drools.compiler.kie.builder.impl.KieContainerImpl.newKieBase(KieContainerImpl.java:217)[168:org.drools.compiler:6.0.0.redhat-6] Expected results: Bundle activation succeeds and the message "KieSession created." is printed in the Fuse console. (Use "features:uninstall my-kie-osgi-sample" to dispose of the created KieSession.)