1

I'm using KieFileSystem.write to load a .drl file dynamically. Does it matter the location where the file is written within the virtual file system? All tutorials I found online seem to suggest src/main/resources/myRules.drl and as far as I can tell rules written to other locations (say myRules.drl) are not being loaded.

I think I read somewhere that Drools scans the classpath for .drl files. Does that mean it also loads files from the physical file system when a virtual one is explicitly created or does the virtual replaces the physical one?

Is there any detail explanation how the rule loading works?

I'm not using maven for my project BTW.

ventsyv
  • 3,316
  • 3
  • 27
  • 49
  • maybe this should help http://stackoverflow.com/questions/23542610/drools-6-0-dynamically-load-rules-at-runtime – piyushj Aug 19 '16 at 05:53

1 Answers1

0

The rule is simple. You need to explicitly tell drools what type of resource you are trying to load. ResourceFactory supports classpath resources, streams, files, etc.

Example

Here is an example on how you can obtain KieBase instance using custom file resources.

List<Resource> resources = Arrays.asList(
    // loads file from "real" filesystem
    ResourceFactory.newFileResource("example.drl")
);

KieServices kieServices = Factory.get();
KieFileSystem kfs = kieServices.newKieFileSystem();
resources.forEach(kfs::write);
KieContainer kieContainer =
    kieServices.newKieContainer(
        kieServices.getRepository().getDefaultReleaseId());

KieBaseConfiguration config =
    Factory.get().newKieBaseConfiguration();
KieBase base = kieContainer.newKieBase(config);
vsminkov
  • 10,912
  • 2
  • 38
  • 50