Is it possible to add Drools to a Java project WEBAPP only adding libs(JARs) manually?

341 views
Skip to first unread message

Desarrollo Theworkshop

unread,
Apr 10, 2017, 9:42:41 AM4/10/17
to Drools Setup
I have a dr file made in KIE Workbench 6.4 and I need to implement on a JDeveloper ADF APP (Drools Embedded/ binary form), I'm already using drools client in another java app but using eclipse wich helps me with Drools plugin, What I have to do to run drools in "binary form" I can't find explanation of this way in documentation If I'm not using Eclipse, learning Maven means too much time to me and I'm very rushed, I saw many times "Drools is just a library, add to the project and it will work", but I'm not finding anywhere wich libraries I have to add to my project to make it work.


"
But I added this libs to my java project and "KieSession" and many other items are not recognized, I'm missing any important lib? Or I misunderstanding the installation?

Thanks in advance, any help will be very helpful!


Desarrollo Theworkshop

unread,
Apr 11, 2017, 8:03:12 AM4/11/17
to Drools Setup
Finally I could import all drools libraries, but now I don't know how to load a drl file and executing rules.

My actual code to run drools:


        KieServices kieServices = KieServices.Factory.get();
        KieModuleModel kieModuleModel = kieServices.newKieModuleModel();

        KieBaseModel kieBaseModel1 = kieModuleModel.newKieBaseModel("KBase1 ")
                                                   .setDefault(true)
                                                   .setEqualsBehavior(EqualityBehaviorOption.EQUALITY)
                                                   .setEventProcessingMode(EventProcessingOption.STREAM);

        KieSessionModel ksessionModel1 = kieBaseModel1.newKieSessionModel("KSession1")
                                                      .setDefault(true)
                                                      .setType(KieSessionModel.KieSessionType.STATEFUL)
                                                      .setClockType(ClockTypeOption.get("realtime"));

        KieFileSystem kfs = kieServices.newKieFileSystem();
        kfs.writeKModuleXML(kieModuleModel.toXML());


        System.out.println("done");
        FileInputStream fis;
        try {
            fis = new FileInputStream("C:\\drools\\test.drl");
            kfs.write("src/main/resources/myDrl.txt", kieServices.getResources()
                                                                 .newInputStreamResource(fis)
                                                                 .setResourceType(ResourceType.DRL));

        } catch (FileNotFoundException e) {
            e.printStackTrace();

        }
        // .newFileSystemResource("C:\\drools\\test.drl").setResourceType(ResourceType.DRL));



        kieServices.newKieBuilder(kfs).buildAll();
        kieContainer = kieServices.newKieContainer(kieServices.getRepository().getDefaultReleaseId());
       
        KieBase kBase = kieContainer.getKieBase();
        KieSession ksession = kBase.newKieSession();
        ksession.insert("hello");
        ksession.fireAllRules();
Reply all
Reply to author
Forward
0 new messages