Created drools Kie session and I get this “class not found exception”

匆匆过客 提交于 2019-12-11 13:04:33

问题


I am new to drools, testing it out to create kie session and while I tried to do that, I get this error. Followed this tutorial to do it

http://javainuse.com/drools_hello_kie

my 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>

my main class is this

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();
        }
    }

}

my error is

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

Can anyone help with why this could be happening? I added the main class, the pom file and my error what I get. I am not able to figure out where the error lies. I did a step by step implementation of the link above.


回答1:


Please add the below dependency into your POM.xml

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


来源:https://stackoverflow.com/questions/51863725/created-drools-kie-session-and-i-get-this-class-not-found-exception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!