1
votes

I'm developing a Maven project using java and Drools 6.2.0, and I'm trying to "bind" a certain DRL file to a KieBase through the kmodule.xml file, but I keep getting the error

WARN org.drools.compiler.kie.builder.impl.AbstractKieModule - No files found for KieBase

when running the project.

I think I've configured everything the right way, as shown in the documentation (Chapter 4.2.2 - Overview - Build, Deploy, Utilize and Run - Building), but can't see where is my mistake.

In this project, I think it's not an option for me to declare/configure Drools by coding, due to the project architecture, that's why I'm using the kmodule.xml approach.

Any suggestion is welcome.


My kmodule.xml (location: src/main/resources/META-INF):

<?xml version="1.0" encoding="UTF-8"?>
<kmodule xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://jboss.org/kie/6.0.0/kmodule">
    <kbase name="departureKB" packages="com.site.myapp.checks.departure">
        <ksession name="departureKS" type="stateless" />
    </kbase>
</kmodule>

My DRL file (dummy) (location: src/main/resources/com/site/myapp/checks/departure):

package com.site.myapp.checks.departure

rule "my rule 1"
    when
        // some conditions
    then
        // something to do
end

My class Departure (only the Drools code) (location: src/com/site/myapp/checks):

channelName = "departure";
KieServices ks = KieServices.Factory.get();
KieContainer kc = ks.getKieClasspathContainer();
String kSessionName = channelName+"KS";
kSession = kc.newStatelessKieSession(kSessionName);

My pom.xml (only the Drools dependencies) :

<dependency>
    <groupId>org.drools</groupId>
    <artifactId>drools-bom</artifactId>
    <version>6.2.0.Final</version>
    <type>pom</type>
</dependency>
<dependency>
    <groupId>org.kie</groupId>
    <artifactId>kie-api</artifactId>
    <version>6.2.0.Final</version>
</dependency>
<dependency>
    <groupId>org.drools</groupId>
    <artifactId>drools-compiler</artifactId>
    <version>6.2.0.Final</version>
    <scope>runtime</scope>
</dependency>
<dependency>
    <groupId>org.drools</groupId>
    <artifactId>named-kiesession</artifactId>
    <version>6.2.0.Final</version>
</dependency>
1
I don't see any obvious problem here. I do have some questions though: Why are you including drools-bom and named-kiesession artifacts? Do you really need them? What's the name of your drl file? - Esteban Aliverti
- The drools-bom artifact I'm not sure, it was included by other guy, but I think it's related with the compilation. - The named-kiesession artifact I've seen it in a tutorial, and have tried it... - My DRL file name is Departure.drl - rjmAmaro

1 Answers

5
votes

The problem is that it's needed to declare in the pom.xml file to include the DRL files.

The pom.xml file should look like this (in my project it's like this, should be similar in others):

<project ...>
   ...
    <build>
        <sourceDirectory>src</sourceDirectory>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>META-INF/kmodule.xml</include>
                    <include>com/site/myapp/checks/departure/Departure.drl</include>
                </includes>
                <targetPath>.</targetPath>
            </resource>
        </resources>
    </build>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.drools</groupId>
                <artifactId>drools-bom</artifactId>
                <version>6.2.0.Final</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.kie</groupId>
            <artifactId>kie-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.drools</groupId>
            <artifactId>drools-compiler</artifactId>
            <scope>runtime</scope>
        </dependency>
    </dependencies>
</project>

Take notice to the changes related with the pom.xml indicated in the Question.
Here, I've changed the location of the drools-bom artifact, it's now in the dependecyManagement tag (this artifact is used for the version control of the artifacts, with this you only need to declared the version of the artifacts one time); and have removed the named-kiesession artifact.