How can we share individual rules between .drl files in JBoss Rules?

不羁的心 提交于 2019-12-23 17:14:54

问题


We are using JBoss Rules (a.k.a. Drools) and have several .drl files that each contain several rules. Is there a way to avoid duplication between files, so that we can define common rules that are available to more than one .drl file?

Unfortunately, there does not seem to be any kind of include or module facility.


回答1:


There is no way of including rules from another .drl file from within a .drl file.

You can however add two .drl files to the same ruleBase and they will work as if they were in the same file.

PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "common.drl" ) ) );
builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "rules1.drl" ) ) );
RuleBase ruleBase  = RuleBaseFactory.newRuleBase();
ruleBase.addPackage( builder.getPackage()  );


来源:https://stackoverflow.com/questions/91917/how-can-we-share-individual-rules-between-drl-files-in-jboss-rules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!