我正在尝试构建示例示例,如本教程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)
看起来它没有从规则文件中读取任何规则。我想念什么吗?