创建了Drools Kie会话,我得到了这个“类未找到异常”

时间:2018-08-15 17:38:02

标签: maven drools kie

我是流口水的新手,对其进行测试以创建kie会话,而当我尝试这样做时,却出现此错误。按照本教程进行操作

http://javainuse.com/drools_hello_kie

我的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.javainuse</groupId>
  <artifactId>drools-hello-world</artifactId>
  <version>0.0.1-SNAPSHOT</version>

<properties>
        <drools.version>6.2.0.Final</drools.version>
</properties>
    <dependencies>
        <dependency>
            <groupId>org.kie</groupId>
            <artifactId>kie-api</artifactId>
            <version>6.2.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.drools</groupId>
            <artifactId>drools-core</artifactId>
            <version>6.2.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.drools</groupId>
            <artifactId>drools-compiler</artifactId>
            <version>6.2.0.Final</version>
        </dependency>

        <dependency>
            <groupId>org.kie</groupId>
            <artifactId>kie-ci</artifactId>
            <version>6.2.0.Final</version>
         </dependency>

    </dependencies>
</project>

我的主要班级是这个

package main;

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

import stateful.Product;

public class StatefulMain {

    public static final void main(String[] args) {
        try {
            KieServices ks = KieServices.Factory.get();
            KieContainer kContainer = ks.getKieClasspathContainer();
//Get the session named kseesion-rule that we defined in kmodule.xml above.
//Also by default the session returned is always stateful. 
            KieSession kSession = kContainer.newKieSession("ksession-rule");

            Product product = new Product();
            product.setType("gold");

            FactHandle fact1;

            fact1 = kSession.insert(product);
            kSession.fireAllRules();

            System.out.println("The discount for the jewellery product "
                    + product.getType() + " is " + product.getDiscount());

        } catch (Throwable t) {
            t.printStackTrace();
        }
    }

}

我的错误是

java.lang.ExceptionInInitializerError
    at main.StatefulMain.main(StatefulMain.java:14)
Caused by: java.lang.RuntimeException: Unable to instance KieServices
    at org.kie.api.KieServices$Factory.<clinit>(KieServices.java:233)
    ... 1 more
Caused by: java.lang.ClassNotFoundException: org.drools.compiler.kie.builder.impl.KieServicesImpl
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at org.kie.api.KieServices$Factory.<clinit>(KieServices.java:231)
    ... 1 more

有人可以帮助解释为什么会这样吗?我添加了主类,pom文件和我得到的错误。我无法找出错误所在。我一步一步地实现了上面的链接。

1 个答案:

答案 0 :(得分:0)

请在您的POM.xml中添加以下依赖项

<dependency>
    <groupId>org.drools</groupId>
    <artifactId>drools-decisiontables</artifactId>
    <version>6.2.0.Final</version>
</dependency>