[rules-users] Adding rules at runtime

Justin King justin.matthew.king at gmail.com
Mon Aug 24 21:03:27 EDT 2009


Hi Everyone,

I found an old example that shows how to add a rule at runtime:

function void addRule(String pkgName, String rule, RuleBase ruleBase ) {
   PackageBuilder builder = new PackageBuilder();
   builder.addPackgeFromDrl( new StringReader( rule ) );
   ruleBase.addPackage ( builder.addPackage() );
}

I'm trying to do a similar thing with Drools 5 but things seem to have
changed. What I want is to add a rule (just as a string) to an already
existing set of rules I've loaded from a drl file (the new rule does not
have to be saved to the actual file though). I see KnowledgeBase has a
remove rule method but no add rule.
I should also note that the set of rules I wish to add to is already
executing (as in I've called *fireUntilHalt()*) I hope this wont make a
difference.

Thanks in advance for any help, this mailing list saves me every time!

Cheers,

Justin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20090825/7402bd12/attachment.html 


More information about the rules-users mailing list