我无法从jbpm业务规则任务中触发规则。似乎该进程未找到规则文件。尝试解释。
首先,我扩展了Drools示例,在我设置RuleFlowGroup的女巫中添加了业务规则任务:
简单地设置processTest.java消息并启动过程:
package com.sample;
import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import com.sample.DroolsTest.Message;
/**
* This is a sample file to launch a process.
*/
public class ProcessTest {
public static final void main(String[] args) {
try {
// load up the knowledge base
KieServices ks = KieServices.Factory.get();
KieContainer kContainer = ks.getKieClasspathContainer();
KieSession kSession = kContainer.newKieSession("ksession-process");
// go !
Message message = new Message();
message.setMessage("Hello Giorgio");
message.setStatus(Message.HELLO);
kSession.insert(message);
// start a new process instance
kSession.startProcess("com.sample.bpmn.hello");
} catch (Throwable t) {
t.printStackTrace();
}
}
}
然后我运行并正确触发脚本任务(“ Hello world”),但在RuleGroup1.drl中找不到规则:
//created on: 21-gen-2019
package com.sample
//list any import classes here.
import com.sample.DroolsTest.Message;
//declare any global variables here
rule "First Giorgio rule"
ruleflow-group "Group1"
when
m : Message( status == Message.HELLO, myMessage : message )
then
System.out.println( "rule0 Group1" );
end
rule "Your First Rule"
ruleflow-group "Group1"
when
//conditions
then
System.out.println( "rule1 Group1" );
end
rule "Your Second Rule"
ruleflow-group "Group1"
//include attributes such as "salience" here...
when
//conditions
then
System.out.println( "rule2 Group1" );
end
关注项目文件夹:
感谢您的帮助。
答案 0 :(得分:1)
确保“规则”文件和“处理”文件位于同一文件夹中。 最重要的是,确保在Rules文件中声明的软件包与其中包含的目录名称以及kmodule.xml中的软件包声明一致。如果它们不同步,则最终将导致您的规则不被解雇。 检查此示例项目。 Using Drools Rules with jBPM
答案 1 :(得分:0)
我决定添加一个kSession.fireAllRules()并将流程和规则文件存储在同一程序包中。
1)修改kmodule.xml以添加ksession名称“ processrules”:
<?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>
<kbase name="dtables" packages="dtables">
<ksession name="ksession-dtables"/>
</kbase>
<kbase name="process" packages="process">
<ksession name="ksession-process"/>
</kbase>
<kbase name="processrules" packages="processrules">
<ksession name="ksession-processrules"/>
</kbase>
</kmodule>