0

I was looking at this example with the KieBase defined as follows:

  <?xml version="1.0" encoding="UTF-8"?>
    <kmodule
        xmlns="http://jboss.org/kie/6.0.0/kmodule">
    <kbase name="kbase1">
        <ksession name="ksession1"/>
    </kbase>
 </kmodule>

I was expecting the drl file to be in src/main/resources/kbase1. I made this assumption because reading the book Mastering JBoss Drools 6, it was indicated that the kbase name is where the drl file should be placed. The sentence reads below:

'Notice that the name attribute of the KieBase is the same as the directory structure that we are using under /src/test/resources/ directory, where the rules are stored. '

However, in the example, the drl file in placed in the following directory: src/main/resources/namedkiesession.

Here is the file: HAL1.drl

  package org.drools.example.api.namedkiesession

   import org.drools.example.api.namedkiesession.Message

   global java.io.PrintStream out

   rule "rule 1" salience 10 when
    m : Message( )
   then
     out.println( m.getName() + ": " +  m.getText() );
   end

  rule "rule 2" when
     Message( text == "Hello, HAL. Do you read me, HAL?" )
  then
    insert( new Message("HAL", "Dave. I read you." ) );
  end

How does this work if the KieBase name is not where the actual drl file is stored? The full source code is here:

https://github.com/kiegroup/drools/blob/6.0.x/drools-examples-api/pom.xml

BreenDeen
  • 623
  • 1
  • 13
  • 42

1 Answers1

0

You have just found an error (or typo) in the book. The name of a KieBase is an arbitrary name you choose and has no relation with the directory structure where the .drl files are located.

The attribute of a <kbase> element that you can use to tell what packages (directories) to include is the packages attribute and not the name attribute If the packages attribute is not specified, then the KieBase will include any artifact (drl, bpmn, dtable, etc.) that is located under the resource directory.

You can find a better explanation of the attributes of a <kbase> in the official Drools' documentation (look for table 4.1).

Note that starting from version 7.18, the semantics of the packages attributes suffered a slight (but fundamental) change as stated in the documentation.

Hope it helps,

Esteban Aliverti
  • 6,259
  • 2
  • 19
  • 31
  • Thank you, I do appreciate this. One thing I have observed though is I've seen many examples where the folder is the same as the name attribute. – BreenDeen Aug 10 '19 at 02:32