下面是调用changeset.xml的主java文件。在没有changeset.xml的情况下使用时,changeset.xml中提供的规则文件在执行时不会执行。
ResourceFactory.getResourceChangeNotifierService().start();
ResourceFactory.getResourceChangeScannerService().start();
ResourceChangeScannerConfiguration sconf = ResourceFactory.getResourceChangeScannerService().newResourceChangeScannerConfiguration();
sconf.setProperty("drools.resource.scanner.interval", "10");
ResourceFactory.getResourceChangeScannerService().configure(sconf);
KnowledgeAgentConfiguration aconf = KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
aconf.setProperty("drools.agent.scanDirectories", "true");
aconf.setProperty("drools.agent.scanResources", "true");
aconf.setProperty("drools.agent.newInstance", "false");
// KnowledgeBuilder kbuilder1 = KnowledgeBuilderFactory.newKnowledgeBuilder();
// kbuilder1.add( ResourceFactory.newFileResource("file:C://Users//latika.vashishtha.in//Workspace 2//AppChangeset1//src//test//resources//change-set.xml"),ResourceType.CHANGE_SET );
KnowledgeAgent knowledgeAgent = KnowledgeAgentFactory.newKnowledgeAgent("AGENT", aconf);
knowledgeAgent.applyChangeSet(ResourceFactory.newFileResource("file:C://Users//latika.vashishtha.in//Workspace 2//AppChangeset1//src//test//resources//Sample.drl" ));
knowledgeAgent.addEventListener(new DebugKnowledgeAgentEventListener());
return knowledgeAgent.getKnowledgeBase();
/ ****************************** Changeset.xml ************* *************** /
<?xml version="1.0" encoding="UTF-8"?>
<change-set xmlns='http://drools.org/drools-5.0/change-set'
xmlns:xs='http://www.w3.org/2001/XMLSchema-instance'
xs:schemaLocation='http://drools.org/drools-5.0/change-set.xsd http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-api/src/main/resources/change-set-1.0.0.xsd'>
<add>
<resource source='C:/Users/latika.vashishtha.in/Workspace 2/AppChangeset1/src/test/resources/Sample.drl' type='DRL'> </resource>
</add>
</change-set>
<?xml version="1.0" encoding="UTF-8"?>
<change-set xmlns='http://drools.org/drools-5.0/change-set'
xmlns:xs='http://www.w3.org/2001/XMLSchema-instance'
xs:schemaLocation='http://drools.org/drools-5.0/change-set.xsd http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-api/src/main/resources/change-set-1.0.0.xsd'>
<add>
<resource source='C:/Users/latika.vashishtha.in/Workspace 2/AppChangeset1/src/test/resources/Sample.drl' type='DRL'> </resource>
</add>
</change-set>
答案 0 :(得分:0)
您正在传递drl而不是更改集
KnowledgeAgentConfiguration aconf = KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
aconf.setProperty("drools.agent.scanDirectories", "true");
aconf.setProperty("drools.agent.scanResources", "true");
aconf.setProperty("drools.agent.newInstance", "false");
KnowledgeBuilder kbuilder1 = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder1.add( ResourceFactory.newFileResource("file:C://Users//latika.vashishtha.in//Workspace 2//AppChangeset1//src//test//resources//Sample.drl"),ResourceType.DRL );
assertFalse( kbuilder.hasErrors());
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
KnowledgeAgent knowledgeAgent = KnowledgeAgentFactory.newKnowledgeAgent("AGENT", kbase, aconf);
knowledgeAgent.applyChangeSet(ResourceFactory.newFileResource("file:C://Users//latika.vashishtha.in//Workspace 2//AppChangeset1//src//test//resources//change-set.xml" ));
knowledgeAgent.addEventListener(new DebugKnowledgeAgentEventListener());
ResourceChangeScannerConfiguration sconf = ResourceFactory.getResourceChangeScannerService().newResourceChangeScannerConfiguration();
sconf.setProperty("drools.resource.scanner.interval", "10");
ResourceFactory.getResourceChangeScannerService().configure(sconf);
ResourceFactory.getResourceChangeNotifierService().start();
ResourceFactory.getResourceChangeScannerService().start();
return knowledgeAgent.getKnowledgeBase();