Първо създайте Java приложение, включете всички базирани на drools 6 двоични зависимости. За това можете да създадете управлявано от Maven java application.include следните зависимости във файла POM.xml.. той ще изтегли всички зависимости във вашето локално хранилище на maven.
<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();
}