Слюни kession правила стрельбы. Похоже, что он не читает файл правил - PullRequest
0 голосов
/ 12 марта 2020

Я пытаюсь создать пример, как показано здесь в этом уроке LINK . Файлы правил такие же, как показано. Файл выполнения выглядит следующим образом:

public class TaxCalculationApp {

    public static void main(String[] args) {

        System.out.println( "Bootstrapping the Rule Engine ..." );      

        KieServices ks = KieServices.Factory.get();
        KieContainer kContainer = ks.getKieClasspathContainer();
        KieSession kSession =  kContainer.newKieSession("ksession-rules");
        KieRuntimeLogger kieLogger = ks.getLoggers().newFileLogger(kSession, "log");


        ItemCity item1 = new ItemCity();
        item1.setPurchaseCity(City.PUNE);
        item1.setTypeofItem(Type.MEDICINES);
        item1.setSellPrice(new BigDecimal(10));
        kSession.insert(item1);

        ItemCity item2 = new ItemCity();
        item2.setPurchaseCity(City.PUNE);
        item2.setTypeofItem(Type.GROCERIES);
        item2.setSellPrice(new BigDecimal(10));
        kSession.insert(item2);

        ItemCity item3 = new ItemCity();
        item3.setPurchaseCity(City.NAGPUR);
        item3.setTypeofItem(Type.MEDICINES);
        item3.setSellPrice(new BigDecimal(10));
        kSession.insert(item3);

        ItemCity item4 = new ItemCity();
        item4.setPurchaseCity(City.NAGPUR);
        item4.setTypeofItem(Type.GROCERIES);
        item4.setSellPrice(new BigDecimal(10));
        kSession.insert(item4);     

        int fired = kSession.fireAllRules();        
        System.out.println( "Number of Rules executed = " + fired );
        System.out.println(item1.getPurchaseCity().toString() + " " + item1.getLocalTax().intValue());
        System.out.println(item2.getPurchaseCity().toString() + " " + item2.getLocalTax().intValue());             
        System.out.println(item3.getPurchaseCity().toString() + " " + item3.getLocalTax().intValue());             
        System.out.println(item4.getPurchaseCity().toString() + " " + item4.getLocalTax().intValue());

        kieLogger.close();

    }   
}

мой файл kmodule -

<?xml version="1.0" encoding="UTF-8"?>
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
    <kbase name="rules" packages="com.sample.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>

Когда я пытаюсь запустить, я получаю следующую ошибку

Bootstrapping the Rule Engine ...
Exception in thread "main" Number of Rules executed = 0
java.lang.NullPointerException
    at com.sample.TaxCalculationApp.main(TaxCalculationApp.java:55)

Looks как это не чтение каких-либо правил из файла правил. Я что-то упустил?

...