[rules-users] dynamic runtime addition of rules

Justin King justin.matthew.king at gmail.com
Mon Sep 7 22:42:33 EDT 2009


Hi Everyone,

I'm having a problem adding a rule to a custom package. I have a drl file in
the com.sample package. I read in that drl file and everything is fine. I
then wish to add another rule to the KnowledgeBase as a String. I'm using
the following code for this (where kbase is the existing KnowledgeBase with
the preloaded rules):

            KnowledgeBuilder kbuilder2 =
KnowledgeBuilderFactory.newKnowledgeBuilder(kbase);

            String rule = "rule \"GeneralClause-2\" " +
            "when " +
                "ObligationComplianceEvent(term == \"term2\", obligation ==
\"obligation1\", level == 2) " +
            "then " +
                "contract.setState(\"Hello\");" +
            "end";

            Resource ruleResource =
ResourceFactory.newReaderResource((Reader) new StringReader(rule));
            kbuilder2.add(ruleResource, ResourceType.DRL);

            kbase.addKnowledgePackages(kbuilder2.getKnowledgePackages());

It appears to fails when I call fireUntilHalt() on my session with the
following exception:

Exception in thread "Thread-1" java.lang.NoClassDefFoundError:
defaultpkg/Rule_GeneralClause_2_0

It appears the new rule was added to the default package, and it relies on
events defined in com.sample so I'm assuming this is the problem. My
question is how can I add this rule to com.sample along with the previously
loaded rules? I'm very desperate here, any help is greatly appreciated!

Cheers,

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


More information about the rules-users mailing list