How to execute Guided decision table rules from workbench in java application?

637 views
Skip to first unread message

hareesh kumar

unread,
Jul 19, 2016, 5:29:07 AM7/19/16
to Drools Usage
Hi,

I am using Drools workbench 6.4.0 FINAL and defined rules using guided decision table.

KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId( "test", "test", "1.0" );
ks.getResources().newUrlResource(url);
KieContainer kieContainer = ks.newKieContainer(releaseId); 

am not able to find how to execute guided decision table rules from remote maven using java application.

Can any one tell me how to do that.... 

Thanks in advance.



Michael Anstis

unread,
Jul 19, 2016, 6:06:00 AM7/19/16
to Drools Usage
Have a look at this, it's a bunch of unit test showing use of a KJAR deployed to Maven. 

--
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.
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/d01fc8f5-7677-4b66-b4fa-8e9b67f66caa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

hareesh kumar

unread,
Jul 19, 2016, 7:10:27 AM7/19/16
to Drools Usage
Thanks @Michael

Actually am trying to integrate workbench rules with java application. I want to define the rules in work bench and execute through java application. 

I have written code like below, 

public static void main(String[] args) {


ReleaseIdImpl releaseId = new ReleaseIdImpl( "vm", "vm", "1.0" );

        KieServices ks = KieServices.Factory.get();

        ks.getResources().newUrlResource(url);

        KieContainer kieContainer = ks.newKieContainer(releaseId);

        // check every 5 seconds if there is a new version at the URL
        KieScanner kieScanner = ks.newKieScanner(kieContainer);
        kieScanner.start(5000L);
       
        Scanner scanner = new Scanner(System.in);
        runRule(kieContainer);
     
    }

    private static void runRule(KieContainer kieKontainer) {
        KieSession kSession = kieKontainer.newKieSession();
        Test test = new Test(0, "", "", "", 1, 15345, 50, true, 1, 0);        
        kSession.insert(test);
        System.out.println(kSession.fireAllRules());
    } 

and response was :

[main] WARN org.kie.scanner.embedder.MavenSettings - Environment variable M2_HOME is not set
[main] INFO org.drools.compiler.kie.builder.impl.KieRepositoryImpl - KieModule was added: ZipKieModule[releaseId=vm:vm:1.0,file=C:\Users\Hareesh\.m2\repository\vm\vm\1.0\vm-1.0.jar]
Fired rules: 0

Is there any mistake in my code, can you please tell me or can you provide any documentation. am spending too much time..

Thanks in advance.

Michael Anstis

unread,
Jul 19, 2016, 9:21:43 AM7/19/16
to Drools Usage
Can you provide all your rule definitions in the test-1.0.jar?

I assume there were no errors when running your test?

Message has been deleted
Message has been deleted
Message has been deleted

hareesh kumar

unread,
Jul 19, 2016, 10:56:42 AM7/19/16
to Drools Usage
Hi @Michael,

I have attached jar file. (Note: .jar is not accepting to attach so renamed it to .jar1)

And here is my java code:

public class Test {

public static void main(String[] args) {

        ReleaseIdImpl releaseId = new ReleaseIdImpl( "test", "Testing", "1.0" );

        KieServices ks = KieServices.Factory.get();

        ks.getResources().newUrlResource(url);

        KieContainer kieContainer = ks.newKieContainer(releaseId);
        KieScanner kieScanner = ks.newKieScanner(kieContainer);
        kieScanner.start(5000L);
       
        Scanner scanner = new Scanner(System.in);
        runRule(kieContainer);
    }

    private static void runRule(KieContainer kieKontainer) {
        KieSession kSession = kieKontainer.newKieSession();
        PersonDetails details = new PersonDetails();   
        details.setAge(20);
        kSession.insert(details);
        System.out.println("Fired rules: " + kSession.fireAllRules());
    } 

}



pom.xml
  <modelVersion>4.0.0</modelVersion>
  <groupId>testkjar</groupId>
  <artifactId>testkjar</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>
  
 <dependency>
   <groupId>org.kie</groupId>
   <artifactId>kie-ci</artifactId>
   <version>6.4.0.Final</version>
  </dependency>
  
  <dependency>
 <groupId>org.drools</groupId>
 <artifactId>drools-compiler</artifactId>
 <version>6.4.0.Final</version>
  <scope>provided</scope>
</dependency>
<dependency>
 <groupId>org.drools</groupId>
 <artifactId>drools-core</artifactId>
 <version>6.4.0.Final</version>
  <scope>provided</scope>
</dependency>
<dependency>
 <groupId>org.kie</groupId>
 <artifactId>kie-internal</artifactId>
 <version>6.4.0.Final</version>
  <scope>provided</scope>
</dependency>
<dependency>
 <groupId>org.kie</groupId>
 <artifactId>kie-api</artifactId>
 <version>6.4.0.Final</version>
  <scope>provided</scope>
</dependency>
<dependency>
 <groupId>org.drools</groupId>
 <artifactId>drools-templates</artifactId>
 <version>6.4.0.Final</version>
  <scope>provided</scope>
</dependency>
<dependency>
 <groupId>org.drools</groupId>
 <artifactId>drools-decisiontables</artifactId>
 <version>6.4.0.Final</version>
  <scope>provided</scope>
</dependency>
<dependency>
   <groupId>org.drools</groupId>
   <artifactId>drools-workbench-models-guided-dtable</artifactId>
   <version>6.4.0.Final</version>
</dependency>

<dependency>
 <groupId>com.thoughtworks.xstream</groupId>
 <artifactId>xstream</artifactId>
 <version>1.4.3</version>
  <scope>provided</scope>
</dependency>
<dependency>
 <groupId>org.slf4j</groupId>
 <artifactId>slf4j-simple</artifactId>
 <version>1.7.2</version>
  <scope>runtime</scope>
</dependency>
  </dependencies>

  <profiles>
    <profile>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <repositories>
   <repository>
     <id>guvnor-m2-repo</id>
     <name>Guvnor M2 Repo</name>
   </repository>
 </repositories>   
    </profile>
  </profiles>
</project>
Testing-1.0.jar1

Michael Anstis

unread,
Jul 19, 2016, 6:38:21 PM7/19/16
to Drools Usage

BCC'ed to a colleague who knows better....

hareesh kumar

unread,
Jul 20, 2016, 6:58:14 AM7/20/16
to Drools Usage
Hi @Michael, any response from your colleague..


am able to print all the rules but not able to fire them..

Shiv Ranjan

unread,
Jan 30, 2017, 4:24:57 AM1/30/17
to Drools Usage
Hi Hareesh,

Were able to execute this? I am facing similar problem

Regards
Shiv

Diptee Warudkar

unread,
Jun 25, 2018, 8:50:32 AM6/25/18
to Drools Usage
Hi,

Did u find a solution for this, i am also facing same issue. When i include the decision table in jar. Am not able to create kiesession.

After debugging i found that it fails in this line in CompositeKnowledgeBuilderImpl.java

 buildResource(packages, ResourceType.GDST, ResourceToPkgDescrMapper.GUIDED_DTABLE_TO_PKG_DESCR);


Thanks,

Diptee

Reply all
Reply to author
Forward
0 new messages