How to add drl file as string without writing with KieFileSystem ??

952 views
Skip to first unread message

Adarsh22X22Singh

unread,
Sep 13, 2017, 3:37:04 AM9/13/17
to Drools Usage
                        KieServices ks = KieServices.Factory.get();
			KieContainer kContainer = ks.getKieClasspathContainer();

			KieSession kSession = kContainer.newKieSession("ksession-rule");

So here i do not want to use " kContainer.newKieSession("ksession-rule"); " to read drl.
I have the rules in String i.e. String drl="Rules";
So what should i do for that ??

Mario Fusco

unread,
Sep 13, 2017, 6:50:07 AM9/13/17
to Drools Usage
If you have your drl code in a Java String the quickest thing to do to create a KieSession out of it is using the KieHelper as it follows:

String drl = ... // your drl is here
KieSession ksession = new KieHelper().addContent(drl, ResourceType.DRL).build().newKieSession();

Note however that the KieHelper is not in drools public API and the it may be subject to change without any warning.

Regards,
Mario

--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+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-usage/f4d9db70-4c75-42e3-89a7-49b456d6404b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Adarsh22X22Singh

unread,
Sep 14, 2017, 7:24:24 AM9/14/17
to Drools Usage
Thank you so much Mario,
I have few questions..
1 - what various formats of rule file is accepted by Drools ?? As I know .drl, .xls. So does it accept Json or Xml ??
2 - Can we write loop in drl file ?
3 - Is there any editor in which we can define the rules in guided table and download the source as .drl file?


On Wednesday, 13 September 2017 16:20:07 UTC+5:30, Mario Fusco wrote:
If you have your drl code in a Java String the quickest thing to do to create a KieSession out of it is using the KieHelper as it follows:

String drl = ... // your drl is here
KieSession ksession = new KieHelper().addContent(drl, ResourceType.DRL).build().newKieSession();

Note however that the KieHelper is not in drools public API and the it may be subject to change without any warning.

Regards,
Mario
On Wed, Sep 13, 2017 at 9:37 AM, Adarsh22X22Singh <adarshs...@gmail.com> wrote:
                        KieServices ks = KieServices.Factory.get();
			KieContainer kContainer = ks.getKieClasspathContainer();

			KieSession kSession = kContainer.newKieSession("ksession-rule");

So here i do not want to use " kContainer.newKieSession("ksession-rule"); " to read drl.
I have the rules in String i.e. String drl="Rules";
So what should i do for that ??

--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.

Michael Anstis

unread,
Sep 14, 2017, 7:27:15 AM9/14/17
to Drools Usage
> 3 - Is there any editor in which we can define the rules in guided table and download the source as .drl file?

The Guided Decision Table Editor produces a "gdst" file that is recognised by KieHelper. See the ResourceType enumeration for different types.

That said you won't be able to download any source from the Workbench. You'll need to clone the repository and extract the source file yourself.

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

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

Adarsh22X22Singh

unread,
Sep 14, 2017, 9:03:33 AM9/14/17
to Drools Usage
Thank You Michael,
Does it accept rules in Json format ??
Reply all
Reply to author
Forward
0 new messages