Đầu tiên tạo ứng dụng Java, bao gồm tất cả các phụ thuộc nhị phân dựa trên drools 6. Để làm được điều đó, bạn có thể tạo ứng dụng java được điều khiển bằng Maven. Bao gồm các phần phụ thuộc sau trong tệp POM.xml .. nó sẽ tải xuống tất cả các phần phụ thuộc trong kho lưu trữ maven cục bộ của bạn.
<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>
cũng chỉ định hồ sơ trong 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>
Trong 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();
}