开发者

Drools 5 load drl rule file from file system

I devloped a custom rule editor able to create drl file and save them in file system under a given directory. (e.g. c:\savedRules\rule.drl). The problem is that once the rule is saved I need to run it with drools engine. In my class I try to load rule in this way:

KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); 
kbuilder.add(ResourceFactory.newClassPathResource("c:\savedRules\rule.drl"), ResourceType.DRL);

but its doesn't work. the exception is "rule.drl cannot be opened because it does not exist" but it actually exists....

What am I doing w开发者_如何学JAVArong? Is there another way to load rules directly from file system?


Try using,

FileInputStream  fis = new FileInputStream(drlFile);
kbuilder.add(ResourceFactory.newInputStreamResource(fis), ResourceType.DRL);

Thanks.


kbuilder.add(ResourceFactory.newClassPathResource("LoopConditionRules.drl"),ResourceType.DRL);

Just add this line and copy your drl file in resource folder of the project, when you will run it will automatically find the file from the project there is no need to give specific path for your file.

Try this way, may be you can get your required result.


Try the below code, this will work.

kbuilder.add(ResourceFactory.newFileResource(drlFileName), ResourceType.DRL);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜