Почему kieServices в файле классе Main имеет значение null?
Почему kieServices в файле классе Main имеет значение null? Используется maven
и drools
в IDE Eclipse
, суть приложения: Приложение для управления бизнес-правилами на основе Drools
.
Все необходимые библиотеки Drools
я поставил. Ниже pom.xml
.
Описание ошибки:
Exception in thread "main" java.lang.NullPointerException:
Cannot invoke "org.kie.api.KieServices.getKieClasspathContainer()" because "kieServices" is null
at com.javainuse.main.Main.main(Main.java:13)
проект находится здесь.
Код проекта:
main.java:
package com.javainuse.main;
import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import com.javainuse.model.Product;
public class Main {
public static void main(String[] args) {
KieServices kieServices = KieServices.Factory.get();
KieContainer kieContainer = kieServices.getKieClasspathContainer();
KieSession kieSession = kieContainer.newKieSession();
Product product = new Product("soda", 5, true, 2);
kieSession.insert(product);
kieSession.fireAllRules();
kieSession.dispose();
}
}
Product.java:
package com.javainuse.model;
public class Product {
public String name;
public int quantity;
public boolean onPromotion;
public int emptyBottles;
public Product(String name, int quantity, boolean onPromotion, int emptyBottles) {
this.name = name;
this.quantity = quantity;
this.onPromotion = onPromotion;
this.emptyBottles = emptyBottles;
}
}
Rules.drl:
package com.rule
import com.javainuse.model.Product
rule "Check promotion"
when
$p : Product(name == "soda", onPromotion == true)
then
System.out.println("The product is on promotion!");
end
rule "Check number of bottles"
when
$p : Product(name == "soda", quantity >= 2)
then
System.out.println("You can exchange two empty bottles for one new bottle!");
end
rule "Check number of empty bottles"
when
$p : Product(name == "soda", emptyBottles >= 2)
then
System.out.println("You can exchange two empty bottles for one new bottle!");
end
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.javainuse</groupId>
<artifactId>lab1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
<version>7.59.0.Final</version>
</dependency>
</dependencies>
</project>