0

I have a drool 6 work bench. I am trying to read the rules from work bench and execute them in stand alone java application. Is there any way to download the drl file using URL from the workbench. Please write the code as well as I am new to drools

user2981996
  • 41
  • 2
  • 5

2 Answers2

0

First create Java application, include all drools 6 based binary dependencies. For that you can create Maven driven java application. include following dependencies in POM.xml file.. it will download all dependencies in your local maven repository.

<parent>
    <groupId>org.drools</groupId>
    <artifactId>drools-multiproject</artifactId>
    <version>6.0.1.Final</version>
</parent>
 <dependencies>      
    <!-- Internal dependencies -->
    <dependency>
        <groupId>org.kie</groupId>
        <artifactId>kie-api</artifactId>
    </dependency>
    <dependency>
        <groupId>org.kie</groupId>
        <artifactId>kie-ci</artifactId>            
    </dependency>
    <dependency>
        <groupId>org.drools</groupId>
        <artifactId>drools-core</artifactId>
    </dependency>
    <dependency>
        <groupId>org.drools</groupId>
        <artifactId>drools-compiler</artifactId>
    </dependency>
    <dependency>
        <groupId>org.drools</groupId>
        <artifactId>drools-decisiontables</artifactId>
    </dependency>
    <dependency>
        <groupId>org.drools</groupId>
        <artifactId>drools-templates</artifactId>
    </dependency>

    <!-- Needed for logging -->
    <dependency>
        <groupId>com.thoughtworks.xstream</groupId>
        <artifactId>xstream</artifactId>
    </dependency>

    <!-- Logging -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
    </dependency>    
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
    </dependency>
    <dependency><!-- For example app logging: configure in src/java/resources/logback.xml -->
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
    </dependency>
</dependencies>

also specify the profile in pom.xml :

<profiles>
    <profile>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <repositories>
            <repository>
                <id>guvnor-m2-repo</id>
                <name>Drools Workbench Repository Group</name>
                <url>http://localhost:4040/kie-drools-wb-distribution-wars-6.0.1.Final-tomcat7.0/maven2/</url>
                <layout>default</layout>
                <releases>
                    <enabled>true</enabled>
                    <updatePolicy>always</updatePolicy>
                </releases>
            </repository>
        </repositories>
    </profile>
</profiles>

In main.java

public static void main(String[] args) {
    ReleaseIdImpl releaseId = new ReleaseIdImpl("groupId", "artifactId", "LATEST");

    KieServices ks = KieServices.Factory.get();

    KieContainer kieContainer = ks.newKieContainer(releaseId);

    KieScanner kScanner = ks.newKieScanner(kieContainer);
    kScanner.start(10000L);             
    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) {
    KieSession newKieSession = kieKontainer.newKieSession();

    //Initiate POJO on which you want to define rule like
    //BankLoan bankLoan = new BankLoan();
      //  bankLoan.setLoanAmount(10000);
       // bankLoan.setLoanPeriod(11);

      //Insert into kieSession
       newKieSession.insert(bankLoan);

    int result = newKieSession.fireAllRules();
    newKieSession.dispose();
}
Ketan Jariwala
  • 225
  • 4
  • 12
  • I tried this approach. But the application was unable to find kie module. I also tried using other approach where I used the jar file directly.But its unable to fire rule. POJO model is defined in the jar, I created same POJO in my standalone java application. Is there some thing wrong in my approach. – user2981996 Aug 06 '14 at 21:35
  • Also can you guide me how to download a single drl file from the workbench. what will be the url for it ? – user2981996 Aug 06 '14 at 23:41
  • have you set the path of repository where your workbench data will reside in POM file????? – Ketan Jariwala Aug 08 '14 at 04:22
  • Yes it is on my remote server. So I gave the location of remote server having the repository . – user2981996 Aug 08 '14 at 19:16
  • Can you post yr problem here...? – Ketan Jariwala Aug 09 '14 at 05:37
0

your pom.xml should have these dependencies

<dependency>
  <groupId>org.drools</groupId>
  <artifactId>drools-compiler</artifactId>
  <version>6.0.0.Final</version>
   <scope>provided</scope>
</dependency>

<dependency>
  <groupId>org.drools</groupId>
  <artifactId>drools-core</artifactId>
  <version>6.0.0.Final</version>
   <scope>provided</scope>
</dependency>

<dependency>
  <groupId>org.kie</groupId>
  <artifactId>kie-internal</artifactId>
  <version>6.0.0.Final</version>
   <scope>provided</scope>
</dependency>

<dependency>
  <groupId>org.kie</groupId>
  <artifactId>kie-api</artifactId>
  <version>6.0.0.Final</version>
   <scope>provided</scope>
</dependency>

<dependency>
  <groupId>org.drools</groupId>
  <artifactId>drools-templates</artifactId>
  <version>6.0.0.Final</version>
   <scope>provided</scope>
</dependency>

<dependency>
  <groupId>org.mvel</groupId>
  <artifactId>mvel2</artifactId>
  <version>2.1.7.Final</version>
   <scope>provided</scope>
</dependency>

<dependency>
  <groupId>org.antlr</groupId>
  <artifactId>antlr-runtime</artifactId>
  <version>3.5</version>
   <scope>provided</scope>
</dependency>

<dependency>
  <groupId>org.apache.poi</groupId>
  <artifactId>poi-ooxml</artifactId>
  <version>3.9</version>
   <scope>provided</scope>
</dependency>


<dependency>
  <groupId>org.drools</groupId>
  <artifactId>drools-decisiontables</artifactId>
  <version>6.0.0.Final</version>
   <scope>provided</scope>
</dependency>

<dependency>
  <groupId>org.eclipse.jdt</groupId>
  <artifactId>org.eclipse.jdt.core</artifactId>
  <version>3.7.1</version>
   <scope>provided</scope>
</dependency>

<dependency>
  <groupId>com.thoughtworks.xstream</groupId>
  <artifactId>xstream</artifactId>
  <version>1.4.3</version>
   <scope>provided</scope>
</dependency>

<dependency>
  <groupId>com.google.protobuf</groupId>
  <artifactId>protobuf-java</artifactId>
  <version>2.5.0</version>
  <scope>provided</scope>
</dependency>

or your classpath file should have these jars

drools-decisiontables-6.0.0.Final.jar
drools-core-6.0.0.Final.jar
kie-internal-6.0.0.Final.jar
kie-api-6.0.0.Final.jar

drools-templates-6.0.0.Final.jar slf4j-api-1.7.5.jar drools-compiler-6.0.0.Final.jar mvel2-2.1.7.Final.jar
antlr-runtime-3.5.jar
poi-ooxml-3.9.jar
poi-3.10-beta2.jar
commons-lang-2.4.jar
xstream-1.4.3.jar
protobuf-java-2.5.0.jar
org.eclipse.jdt.core-3.7.1.jar

skk
  • 151
  • 1
  • 2
  • 9