पहले जावा एप्लिकेशन बनाएं, सभी ड्रोल 6 आधारित बाइनरी निर्भरताएं शामिल करें। उसके लिए आप मावेन संचालित जावा एप्लिकेशन बना सकते हैं। POM.xml फ़ाइल में निम्नलिखित निर्भरताएँ शामिल करें .. यह आपके स्थानीय मावेन रिपॉजिटरी में सभी निर्भरताओं को डाउनलोड करेगा।
<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>
प्रोफ़ाइल को 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>
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();
}