1

Installed drools workbench 6.4.0 Final and defined guided rules in workbench.

Getting below exception if am trying to execute rules from java application.

Exception in thread "main" java.lang.RuntimeException: Cannot find KieModule: org.mydemo:myDemo:1.0
at org.drools.compiler.kie.builder.impl.KieServicesImpl.newKieContainer(KieServicesImpl.java:117)
at org.drools.compiler.kie.builder.impl.KieServicesImpl.newKieContainer(KieServicesImpl.java:111)
at com.test.Test.main(Test.java:51)

Followed online resources and related questions, but still am not able to solve the problem.

This is one of the related link.

My java project dependencies and profile.

  <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>com.thoughtworks.xstream</groupId>
      <artifactId>xstream</artifactId>
      <version>1.4.3</version>
       <scope>provided</scope>
    </dependency>

<profile>
  <activation>
    <activeByDefault>true</activeByDefault>
  </activation>
  <repositories>
    <repository>
      <id>guvnor-m2-repo</id>
      <name>Guvnor M2 Repo</name>
      <url>http://ip:8080/drools-wb/maven2/</url>
    </repository>
  </repositories>      
</profile>

my Java code here :

    public static void main(String[] args) {
    String url = "http://ip:8080/drools-wb/maven2wb/org/mydemo/myDemo/1.0/myDemo-1.0.jar";

    // make sure you use "LATEST" here!
    ReleaseIdImpl releaseId = new ReleaseIdImpl("org.mydemo", "myDemo", "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);
    // alternatively:
    // kieScanner.scanNow();

    Scanner scanner = new Scanner(System.in);
    while (true) {
        runRule(kieContainer);
        System.out.println("Press enter in order to run the test again....");
        scanner.nextLine();
    } 


}

private static void runRule(KieContainer kieKontainer) {
    StatelessKieSession kSession = kieKontainer.newStatelessKieSession("testSession");
    kSession.setGlobal("out", System.out);
    kSession.execute("testRuleAgain");
} 

Can anyone please help me, i am new to drools and spent almost 2 days to solve this issue.

Community
  • 1
  • 1
Hareesh Kumar
  • 63
  • 2
  • 8
  • Does the link work if you put it into your browser. If it starts downloading the jar then you know everything works to that point and the problem is in this code. – Toni Rikkola Aug 11 '16 at 12:49

1 Answers1

0

It might be the url you are using, try changing it to:

http://ip:8080/drools-wb/maven2/org/mydemo/myDemo/1.0/myDemo-1.0.jar

i.e. maven2 NOT maven2b

then try that in a web browser. If you need authentication then this works for me when Drools is hosted on Tomcat and has basic authentication turned on.

    KieServices ks = KieServices.Factory.get();

    KieResources resources = ks.getResources();
    UrlResource urlResource = (UrlResource) resources.newUrlResource(url);
    urlResource.setUsername("admin");
    urlResource.setPassword("admin");
    urlResource.setBasicAuthentication("enabled");

I found this blog post very helpful, it might help you even though you are not using Spring.

http://reypader.github.io/2016/01/06/spring-drools.html

looseend
  • 261
  • 2
  • 6