Ruletemplate declaration in kmodule.xml

593 views
Skip to first unread message

Alex Vincent

unread,
Feb 26, 2016, 6:08:16 PM2/26/16
to Drools Setup
Hi,

I'm trying to use rule templates with Drools 6.4 Beta by specifying it in my kmodule.xml.
However when I start the engine the template does not seem to get loaded and the rules don't seem to get generated.

I don't get any error and I also noticed that no matter what values I specify in dtable and template attributes in my kmodule.xml the engine will not complain. I tried to set the log level to trace but it does not seem to give any information as to whether those files are loaded.

I have some other rules on my classpath that work fine. 

kmodule.xml:

<?xml version="1.0" encoding="UTF-8"?>
    <kbase name="KBase1" packages="process, rules">
    <ruleTemplate dtable="/C:/Users/alex/Documents/Git/DroolsParser/src/main/resources/decision tables/DuplicateFacts.xls"
                  template="/C:/Users/alex/Documents/Git/DroolsParser/src/main/resources/rule templates/tpl_duplicate_facts.drt"
                  row="2" col="2"/>
        <ksession name="KSession1"/>
    </kbase>
</kmodule>

Java code to create the session:

KieServices ks = KieServices.Factory.get()
KieContainer kContainer = ks.getKieClasspathContainer()
kSession = kContainer.newKieSession("KSession1")


Is there any way to make it work? Otherwise how can I generate my rules based on a rule template and a decision table using the API? I found some examples but with the old deprecated API (i.e. KnowledgeBase...)

Thanks a lot

Alex

Michael Anstis

unread,
Feb 26, 2016, 6:15:08 PM2/26/16
to drools...@googlegroups.com

There are numerous unit tests for kmodule based templates and decision tables (sorry I forget which module they're in - and I'm out on my phone)... so they definitely *can* be used.

The paths in your kmodule look a bit duff (for Windows). Try removing the leading slash.

--
You received this message because you are subscribed to the Google Groups "Drools Setup" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-setup...@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-setup/a9e14fa9-8412-40ea-9917-79482fc06583%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Anstis

unread,
Feb 26, 2016, 6:22:51 PM2/26/16
to drools...@googlegroups.com

SimpleRuleTemplateExample in drools/drools-examples shows use of templates. There's a similar test in the decisiontables package.

Jeff Jensen

unread,
Feb 26, 2016, 6:23:00 PM2/26/16
to Drools Setup
There are a few potential issues with your kmodule config.  To start, try these changes:

* spaces in your dir names: Java and Drools may or may not handle that correctly depending on code used to load the file in that path; may need to remove them or use %20 (URL encoding)

* change the file paths from fully qualified to classpath packages, such as:
dtable="decision tables/DuplicateFacts.xls"
template="rule templates/tpl_duplicate_facts.drt"


Alex Vincent

unread,
Feb 26, 2016, 7:23:06 PM2/26/16
to Drools Setup
Thanks Michael.

I will adjust my code based on that and let you know.

It would be nice if we can get a warning message if the template file or the decision table file could not be found. Also what are the row and col attributes? Do I have to modify the row value whenever I add new data to my decision table?

Alex Vincent

unread,
Feb 26, 2016, 7:23:51 PM2/26/16
to Drools Setup
Thanks Jeff.

I'll try your suggestions.

Michael Anstis

unread,
Feb 26, 2016, 7:29:13 PM2/26/16
to drools...@googlegroups.com

I agree some form of error would be better than none - can you please create a new DROOLS JIRA? As far as I understand the row and column attributes point to the column and first row containing your data; so provided you append additional rows you should not need to change those values.

Alex Vincent

unread,
Feb 26, 2016, 11:08:00 PM2/26/16
to Drools Setup
Works better now. I also forgot to add the directories to the packages attribute of the kbase element. This works for me:
    <kbase name="KBase1" packages="process, rules, decisiontables, ruletemplates">
    <ruleTemplate dtable="decisiontables/dt_duplicate_facts.xls"
                  template="ruletemplates/tpl_duplicate_facts.drt"
                  row="2" col="2"/>
        <ksession name="KSession1"/>
    </kbase>
</kmodule>

I will create the JIRA ticket to request the improvement.
Reply all
Reply to author
Forward
0 new messages