无法构建kmodule.xml

时间:2017-06-29 11:15:16

标签: drools

我尝试为SOA环境设置Drools规则。因此,我需要使用xmlparser-2.0。我使用解析器将XMLDocument类型输入转换为用作规则引擎事实的自定义模型。

我的问题是当xmlparser作为库添加时,KieContainer无法实例化KieSession。 此时我得到一个无法构建kmodule.xml错误的索引。

我查了双课,这不是问题。

我正在运行此示例代码

import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;

public class DroolsTest {


    public static final void main(String[] args) {
        try {
            // load up the knowledge base
            KieServices ks = KieServices.Factory.get();
            KieContainer kContainer = ks.getKieClasspathContainer();
            KieSession kSession = kContainer.newKieSession("ksession-rules");

            // go !
            Message message = new Message();
            message.setMessage("Hello World");
            message.setStatus(Message.HELLO);
            kSession.insert(message);
            kSession.fireAllRules();
        } catch(Throwable t) {
            t.printStackTrace();
        }
    }

    public static class Message {

        public static final int HELLO = 0;
        public static final int GOODBYE = 1;

        private String message;

        private int status;

        public String getMessage() {
            return this.message;
        }

        public void setMessage(String message) {
            this.message = message;
        }

        public int getStatus() {
            return this.status;
        }

        public void setStatus(int status) {
            this.status = status;
        }
    }
}

这是在导入xmlparser-2.0时运行DroolsTest的日志记录

2017-06-29 12:53:13 INFO  ClasspathKieProject:131 - Found kmodule: file:/C:/Users/A653219/workspace/rules-engine/target/classes/META-INF/kmodule.xml
2017-06-29 12:53:13 DEBUG ClasspathKieProject:400 - KieModule URL type=file url=/C:/Users/A653219/workspace/rules-engine/target/classes
2017-06-29 12:53:14 ERROR ClasspathKieProject:124 - Unable to build index of kmodule.xml url=file:/C:/Users/A653219/workspace/rules-engine/target/classes/META-INF/kmodule.xml

    2017-06-29 12:53:14 ERROR KieContainerImpl:681 - Unknown KieSession name: ksession-rules
    java.lang.NullPointerException
        at com.sample.DroolsTest.main(DroolsTest.java:24)

这是kmodule.xml

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

    <kbase name="rules" packages="rules">
        <ksession name="ksession-rules"/>
    </kbase>

    <kbase name="dtables" packages="dtables">
        <ksession name="ksession-dtables"/>
    </kbase>

    <kbase name="process" packages="process">
        <ksession name="ksession-process"/>
    </kbase>

</kmodule>

这是应该如何运作的。

2017-06-29 12:51:22 INFO  ClasspathKieProject:131 - Found kmodule: file:/C:/Users/A653219/workspace/rules-engine/target/classes/META-INF/kmodule.xml
2017-06-29 12:51:22 DEBUG ClasspathKieProject:400 - KieModule URL type=file url=/C:/Users/A653219/workspace/rules-engine/target/classes
2017-06-29 12:51:22 DEBUG ClasspathKieProject:293 - Found and used pom.properties C:\Users\A653219\workspace\rules-engine\target\classes\META-INF\maven\nl.dictu.vers\rules-engine\pom.properties
2017-06-29 12:51:22 DEBUG ClasspathKieProject:118 - Discovered classpath module nl.dictu.vers:rules-engine:1.0.0-SNAPSHOT
2017-06-29 12:51:22 INFO  KieRepositoryImpl:113 - KieModule was added: FileKieModule[releaseId=nl.dictu.vers:rules-engine:1.0.0-SNAPSHOT,file=C:\Users\A653219\workspace\rules-engine\target\classes]
2017-06-29 12:51:25 DEBUG KnowledgeBaseImpl:196 - Starting Engine in PHREAK mode
2017-06-29 12:51:26 DEBUG Configuration:87 - loading default configuration
2017-06-29 12:51:26 DEBUG Configuration:94 - no configuration file found, using default settings
2017-06-29 12:51:26 DEBUG BitronixContext:51 - binding transaction manager at name 'java:comp/UserTransaction'
2017-06-29 12:51:26 DEBUG BitronixContext:54 - binding synchronization registry at name 'java:comp/TransactionSynchronizationRegistry'
2017-06-29 12:51:26 DEBUG BitronixContext:72 - looking up 'java:comp/BeanManager'
2017-06-29 12:51:26 DEBUG BitronixContext:51 - binding transaction manager at name 'java:comp/UserTransaction'
2017-06-29 12:51:26 DEBUG BitronixContext:54 - binding synchronization registry at name 'java:comp/TransactionSynchronizationRegistry'
2017-06-29 12:51:26 DEBUG BitronixContext:72 - looking up 'java:comp/env/BeanManager'
Hello World
Goodbye cruel world

依赖条件

<dependency>
            <groupId>org.kie</groupId>
            <artifactId>kie-api</artifactId>
            <version>6.5.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.drools</groupId>
            <artifactId>drools-core</artifactId>
            <version>6.5.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.drools</groupId>
            <artifactId>drools-decisiontables</artifactId>
            <version>6.5.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jbpm</groupId>
            <artifactId>jbpm-test</artifactId>
            <version>6.5.0.Final</version>
        </dependency>

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,我做了一个mvn dependency:tree,发现我的一个罐子引起了这个问题:

[INFO] | +- xerces:xercesImpl:jar:2.4.0:compile

我将此添加为对该依赖项的排除,并且有效。

   <dependency>
        <groupId>mygroup</groupId>
        <artifactId>somejar</artifactId>
        <version>2.4</version>
        <exclusions>
            <exclusion>
                <groupId>com.thoughtworks.xstream</groupId>
                <artifactId>xstream</artifactId>
            </exclusion>
            <exclusion>
                <groupId>xerces</groupId>
                <artifactId>xercesImpl</artifactId>
            </exclusion>
        </exclusions>