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

We use JBoss Rules (aka Drools) and have several .drl files, each of which contains several rules. Is there a way to avoid duplication between files so that we can define the general rules available for multiple .drl files?

Unfortunately, it looks like there are no include or module objects.

+3
source share
1 answer

Cannot include rules from another .drl file from a .drl file.

However, you can add two .drl files to the same rule base, 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()  );
+2
source

Source: https://habr.com/ru/post/1697119/


All Articles