droolsredhatdrools-kie-serverredhat-brmsredhat-bpm

How to execute drools kjar locally using java application and without using kie-server containers?


I need to create the kjar from a drools rule project and use it in another java application as a dependency. How can I execute the kjar in the java application in embedded mode without using any kie-server?


Solution

  • You simply need to include the appropriate kie libraries into your application and then you simply call it where appropriate. The code to set this up might look something like this:

    KieServices ks = KieServices.Factory.get();
    KieContainer kContainer = ks.getKieClasspathContainer();
    KieSession kSession = kContainer.newKieSession("ksession2");
    kSession.setGlobal("out", out);
    
    kSession.insert(new Message("Dave", "Hello, HAL. Do you read me, HAL?"));
    kSession.fireAllRules();
    
    kSession.insert(new Message("Dave", "Open the pod bay doors, HAL."));
    kSession.fireAllRules();
    

    You should really go through the documentation. You should look at this whole thing but the examples in the docs address what you're trying to do: Drools Documentation