1
votes

As a proof of concept, I have used Drools workbench to create data objects and DRL files. I created the jar file and deployed to kie server (with container). All done through workbench UI. I used KIE REST services from my c# application to post the input object via XML (using batch-execution) to fire the rules and I got the response that I was looking for.

But in real scenario, we will have our own rule editor (for ease of use) to create rules based on attributes from existing objects. Once the rule is saved in our DB, our plan is to generate the DRL file along with data objects.

My question is how to take this DRL file and build it as jar file?

Kie container needs a jar file with data objects and DRL file. Has anyone else done something similar?

I am trying to find the best way to deploy my drools rules file. Other alternative could be to use IKVM to generate dlls from drools jar file and integrate drools in my application.

2

2 Answers

2
votes

I think this has been asked and answered before, but here it is once more, code to compile DRL into a KieBase or KieSession.

public KieBase build( String drlPath ) throws Exception {
    KieServices kieServices = KieServices.Factory.get();
    KieFileSystem kfs = kieServices.newKieFileSystem();
    FileInputStream fis = new FileInputStream( drlPath );
    kfs.write( "src/main/resources/some.drl",
                kieServices.getResources().newInputStreamResource( fis ) );
    KieBuilder kieBuilder = kieServices.newKieBuilder( kfs ).buildAll();
    Results results = kieBuilder.getResults();
    if( results.hasMessages( Message.Level.ERROR ) ){
        System.out.println( results.getMessages() );
        throw new IllegalStateException( "### errors ###" );
    }
    KieContainer kieContainer =
        kieServices.newKieContainer( kieServices.getRepository().getDefaultReleaseId() );

    KieBase kieBase = kieContainer.getKieBase();
    return kieBase;
}
0
votes

I ended up converting drools 6.2 to .net dll using IKVM. Here is the post that i created to show how to do it:

http://droolstonet.blogspot.com/2015/05/how-to-use-drools-62-in-net-using-ikvm.html