How to access DRL files outside of the classpath?

4,498 views
Skip to first unread message

Johnny Swarthout

unread,
Nov 8, 2017, 12:31:12 PM11/8/17
to Drools Setup

Hello,

 

We have been working on moving from drools version 5.3.1 to 7.0.0. As well as moving from guvnor to kie workbench.

Before making this move we have been storing our DRL file outside of our Rule Engine project classpath and it has been working great.

When we tried to do this with version 7.0.0, our Rules Engine project could not find our DRL's. When moving the DRLs into the classpath

it can find the rules and they fire like they are supposed to. Is there a way that we could store the DRL files outside

of the classpath and still have our Rules Engine project find them? We would like to keep the DRL files off the classpath as this may

cause frequent code deployments. Plus it is much easier to see and update the DRL files when they are stored on a local path.

 

For reference, we are using eclipse neon 3, jdk8, and JBoss EAP 7.0 server.

 

Thanks,

Johnny

Pavan Nannapaneni

unread,
Nov 9, 2017, 4:38:39 PM11/9/17
to Drools Setup
Hi Johnny,

You can fetch the rules remotely using your application by downloading the JAR file of the rules from Drools Workbench and include it's contents into class-path. To be able to do this, you need to add the artifact as a KieModule into your application's KieRepository. The "source" of the KieModule will come from the data contained in the downloaded rule artifact which is declared as a org.drools.core.io.impl.UrlResource. if you are using spring, below here is the sample code. You can use kieScanner to get the latest version of rules from workbench without redeploying.


@Bean
public KieContainer kieContainer() throws IOException {
    KieServices ks = KieServices.Factory.get();

    KieResources resources = ks.getResources();
    UrlResource urlResource = (UrlResource) resources.newUrlResource(url);
    urlResource.setUsername("drools-user");
    urlResource.setPassword("password");
    urlResource.setBasicAuthentication("enabled");
    InputStream stream = urlResource.getInputStream();

    KieRepository repo = ks.getRepository();
    KieModule k = repo.addKieModule(resources.newInputStreamResource(stream));
    return ks.newKieContainer(k.getReleaseId());
}


-Pavan

Johnny Swarthout

unread,
Nov 14, 2017, 3:12:47 PM11/14/17
to Drools Setup
Thank you.

Abhijit Humbe

unread,
Nov 14, 2017, 10:02:56 PM11/14/17
to drools...@googlegroups.com
There is one more approach available to access rules those are not available in classpath:

 KieServices kServices = KieServices.Factory.get();

KieFileSystem kfs = kServices.newKieFileSystem();
KieRepository kr = kServices.getRepository();
file = new File("/NotBackedUp/Download/SampleRules/Sample.drl");
resource = kServices.getResources().newFileSystemResource(file).setResourceType(ResourceType.DRL);
kfs.write(resource);

file = new File("/NotBackedUp/Download/SampleRules/Sample2.drl");
resource = kServices.getResources().newFileSystemResource(file).setResourceType(ResourceType.DRL);
kfs.write(resource);

KieBuilder kb = kServices.newKieBuilder(kfs);
kb.buildAll();
KieContainer kContainer = kServices.newKieContainer(kr.getDefaultReleaseId());
KieSession kSession = kContainer.newKieSession();

With this approach you will be able to load rules those are not in classpath but available somewhere in filesystem
Hope this helps.


Abhijit Humbe

--
You received this message because you are subscribed to the Google Groups "Drools Setup" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-setup+unsubscribe@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-setup/7e3044ad-2d19-4694-9997-8b6aea2675b5%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Johnny Swarthout

unread,
Nov 15, 2017, 11:00:07 AM11/15/17
to Drools Setup
This is very similar to the approach we ended up taking.  So yes, good solution.  Thank you.

Abhijit Humbe

To unsubscribe from this group and stop receiving emails from it, send an email to drools-setup...@googlegroups.com.

To post to this group, send email to drools...@googlegroups.com.

shashank patel

unread,
Apr 9, 2018, 5:18:49 AM4/9/18
to Drools Setup

Hi,


 In which class  i  should make  changes and  after   building  the    jar(Which   jar)  how  i  should  proceed.
I am  new to  drools .
Can anybody  help  me  on this.
Becoz  it  is urgent.
Reply all
Reply to author
Forward
0 new messages