沉默了,还是继续沉默。
原来一直使用的一种方式,今天才发现有一种其他的方式
代码:
package com.sample;
import org.drools.RuleBase;
import org.drools.StatefulSession;
import org.drools.agent.RuleAgent;
public class DirTest {
/**
* @param args
*/
private static StatefulSession session;
public static void main(String[] args) throws Exception {
// TODO 自动生成方法存根
//规则库
RuleBase rulebase=loadRule();
session=rulebase.newStatefulSession();
session.fireAllRules();
//工作记忆
}
//用代理Agent的方式读取规则
private static RuleBase loadRule()throws Exception
{
RuleAgent agent=RuleAgent.newRuleAgent("/chen.properties");
RuleBase ruleBase=agent.getRuleBase();
return ruleBase;
}
}
//properties文件
chen.properties文件
newInstance=true
dir=src/main/rules
规则文件:
#created on: 2009-5-28
package test
#list any import classes here.
#declare any global variables here
rule "Your First Rule"
when
#conditions
then
#actions
System.out.println("你好!2009年5月28日22:36:37");
end
rule "Your Second Rule"
#include attributes such as "salience" here...
when
#conditions
then
#actions
end
结果输出:
RuleAgent(default) INFO (Thu May 28 22:36:44 CST 2009): Configuring with newInstance=true, secondsToRefresh=-1
RuleAgent(default) INFO (Thu May 28 22:36:44 CST 2009): Configuring package provider : DirectoryScanner scanning dir: src\main\rules found 3 file(s).
RuleAgent(default) INFO (Thu May 28 22:36:47 CST 2009): Applying changes to the rulebase.
RuleAgent(default) INFO (Thu May 28 22:36:47 CST 2009): Creating a new rulebase as per settings.
RuleAgent(default) INFO (Thu May 28 22:36:47 CST 2009): Adding package called test
RuleAgent(default) INFO (Thu May 28 22:36:47 CST 2009): Adding package called com.sample
你好!2009年5月28日22:36:37
端午节
天河五山...