我正在尝试执行以下程序,但是timesheet.drl
文件未得到调用,仅给出o / p:最终时间表状态为null
。无法找到问题所在。
资源:https://www.youtube.com/watch?v=POVe4QY_9p8
DroolDemoMain.Java
package com.sample;
import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
public class DroolDemoMain {
public static void main(String[] args) {
try {
KieServices ks = KieServices.Factory.get();
KieContainer kContainer = ks.getKieClasspathContainer();
KieSession kSession = kContainer.newKieSession("ksession-rules");
Timesheet timesheet = getTimesheetValues();
kSession.insert(timesheet);
kSession.fireAllRules();
System.out.println("Final timesheet status "+ timesheet.getPayStatus());
}
catch(Throwable t) {
t.printStackTrace();
}
}
private static Timesheet getTimesheetValues() {
Timesheet timesheet = new Timesheet();
timesheet.setEmployeeHours(5);
timesheet.setProjectBudgetOk(true);
timesheet.setOverlappingTimesheet(false);
return timesheet;
}
}
Timesheet.java
package com.sample;
public class Timesheet {
private int employeeHours;
private boolean projectBudgetOk;
private boolean duplicateTimesheet;
private boolean overlappingTimesheet;
private String payStatus;
public int getEmployeeHours() {
return employeeHours;
}
public void setEmployeeHours(int employeeHours) {
this.employeeHours = employeeHours;
}
public boolean isProjectBudgetOk() {
return projectBudgetOk;
}
public void setProjectBudgetOk(boolean projectBudgetOk) {
this.projectBudgetOk = projectBudgetOk;
}
public boolean isDuplicateTimesheet() {
return duplicateTimesheet;
}
public void setDuplicateTimesheet(boolean duplicateTimesheet) {
this.duplicateTimesheet = duplicateTimesheet;
}
public boolean isOverlappingTimesheet() {
return overlappingTimesheet;
}
public void setOverlappingTimesheet(boolean overlappingTimesheet) {
this.overlappingTimesheet = overlappingTimesheet;
}
public String getPayStatus() {
return payStatus;
}
public void setPayStatus(String payStatus) {
this.payStatus = payStatus;
}
}
timesheet.drl
package com.sample
import com.sample.Timesheet;
rule"Hours Less"
when
timesheet:Timesheet(employeeHours<8)
then
System.out.println("Employee hours Less Payment Denied");
timesheet.setPayStatus("Denied");
end
kmodule.xml
<?xml version="1.0" encoding="UTF-8"?>
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
<kbase name="rules" packages="rules">
<ksession name="ksession-rules"/>
</kbase>
</kmodule>
谁能向我解释我的代码出了什么问题以及成功执行该怎么办?
答案 0 :(得分:0)
在您的kmodule.xml中,包值错误。它应该与您提供给int drl文件的软件包相匹配。