[rules-users] Drools running in OSGi

diego.vera at capgemini-sdm.com diego.vera at capgemini-sdm.com
Wed Sep 9 16:43:57 EDT 2009


Hi all,

I am trying to run Drools as a bundle with Equinox, however I found an issue with Drools 5 with the classloader, apparently Drools 5 does not always uses the classloader that I pass in the configuration (PackageBuilderConfiguration). Then I decided to test it with Drools 4.0.7 and I do not have the classloader problem anymore but I got the following error (NoSuchMethodError) when I execute stateFulSession.fireAllRules, below is the stack.

I am trying to run it with Equinox 3.4 and I reviewed that all the dependencies are ok. The .drl file is compiled successfully, see the code that I am using below.

I followed the sample publishe in: http://www.dynamicjava.org/articles/osgi-integration/drools-osgi

And I tried with the bundles published by spring and I also tried with my own sample but I get the same error. 


Does anybody used successfully Drools 4.0.7 or 5 in OSGi successfully? What should I change to have my code running in OSGi?


Thanks in advance,


The Code:

        InputStreamReader source = new InputStreamReader( this.getClass.getResourceAsStream( "helloWorld.drl" ) );
                
        OsgiEnvironmentClassLoader classLoader =  
                 new OsgiEnvironmentClassLoader(bundleContext,  
                     Thread.currentThread().getContextClassLoader(),  
                     bundleContext.getBundle());        
                
        
        PackageBuilderConfig packageBuilderConfig = new PackageBuilderConfiguration(classLoader, null); 
        	
        PackageBuilder builder = new PackageBuilder(packageBuilderConfig);

        //this wil parse and compile in one step
        builder.addPackageFromDrl( source );
        
        // Check the builder for errors
        if ( builder.hasErrors() ) {
            System.out.println( builder.getErrors().toString() );
            throw new RuntimeException( "Unable to compile \"helloWorld.drl\".");
        }

        //get the compiled package (which is serializable)
        Package pkg = builder.getPackage();
        
        Package ruleBaseConfig = new RuleBaseConfiguration() 
        ruleBaseConfig.setClassLoader(classLoader);
        //add the package to a rulebase (deploy the rule package).
        RuleBase ruleBase = RuleBaseFactory.newRuleBase(ruleBaseConfig);
        
        ruleBase.addPackage( pkg );
        
        StateFulSession session = ruleBase.newStatefulSession();
	  
	    session.fireAllRules();


The Exception:


INFO: bundle changed: TopicMapEditorService
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActiv
ator(BundleContextImpl.java:1028)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(Bund
leContextImpl.java:984)
        at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(Bundl
eHost.java:344)
        at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(Abstrac
tBundle.java:267)
        at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(Abstrac
tBundle.java:259)
        at org.eclipse.osgi.framework.internal.core.FrameworkCommandProvider._st
art(FrameworkCommandProvider.java:254)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.osgi.framework.internal.core.FrameworkCommandInterpreter.
execute(FrameworkCommandInterpreter.java:150)
        at org.eclipse.osgi.framework.internal.core.FrameworkConsole.docommand(F
rameworkConsole.java:302)
        at org.eclipse.osgi.framework.internal.core.FrameworkConsole.console(Fra
meworkConsole.java:287)
        at org.eclipse.osgi.framework.internal.core.FrameworkConsole.run(Framewo
rkConsole.java:223)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoSuchMethodError: org.drools.WorkingMemory.fireAllRules()I

        at org.topicology.security.TSecurity.initialize(TSecurity.scala:49)
        at org.topicology.TMEditorService.Activator.start(Activator.scala:28)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl$2.run(Bund
leContextImpl.java:1009)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActiv
ator(BundleContextImpl.java:1003)
        ... 14 more
Nested Exception:
java.lang.NoSuchMethodError: org.drools.WorkingMemory.fireAllRules()I
        at org.topicology.security.TSecurity.initialize(TSecurity.scala:49)
        at org.topicology.TMEditorService.Activator.start(Activator.scala:28)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl$2.run(Bund
leContextImpl.java:1009)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActiv
ator(BundleContextImpl.java:1003)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(Bund
leContextImpl.java:984)
        at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(Bundl
eHost.java:344)
        at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(Abstrac
tBundle.java:267)
        at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(Abstrac
tBundle.java:259)
        at org.eclipse.osgi.framework.internal.core.FrameworkCommandProvider._st
art(FrameworkCommandProvider.java:254)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.osgi.framework.internal.core.FrameworkCommandInterpreter.
execute(FrameworkCommandInterpreter.java:150)
        at org.eclipse.osgi.framework.internal.core.FrameworkConsole.docommand(F
rameworkConsole.java:302)
        at org.eclipse.osgi.framework.internal.core.FrameworkConsole.console(Fra
meworkConsole.java:287)
        at org.eclipse.osgi.framework.internal.core.FrameworkConsole.run(Framewo
rkConsole.java:223)
        at java.lang.Thread.run(Unknown Source)
Nested Exception:
java.lang.NoSuchMethodError: org.drools.WorkingMemory.fireAllRules()I
        at org.topicology.security.TSecurity.initialize(TSecurity.scala:49)
        at org.topicology.TMEditorService.Activator.start(Activator.scala:28)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl$2.run(Bund
leContextImpl.java:1009)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActiv
ator(BundleContextImpl.java:1003)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(Bund
leContextImpl.java:984)
        at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(Bundl
eHost.java:344)
        at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(Abstrac
tBundle.java:267)
        at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(Abstrac
tBundle.java:259)
        at org.eclipse.osgi.framework.internal.core.FrameworkCommandProvider._st
art(FrameworkCommandProvider.java:254)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.osgi.framework.internal.core.FrameworkCommandInterpreter.
execute(FrameworkCommandInterpreter.java:150)
        at org.eclipse.osgi.framework.internal.core.FrameworkConsole.docommand(F
rameworkConsole.java:302)
        at org.eclipse.osgi.framework.internal.core.FrameworkConsole.console(Fra
meworkConsole.java:287)
        at org.eclipse.osgi.framework.internal.core.FrameworkConsole.run(Framewo
rkConsole.java:223)
        at java.lang.Thread.run(Unknown Source)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20090909/36efd08e/attachment.html 


More information about the rules-users mailing list