Maak eerst een Java-toepassing, inclusief alle op kwijlen 6 gebaseerde binaire afhankelijkheden. Daarvoor kun je Maven-gestuurde java-applicatie maken. Neem de volgende afhankelijkheden op in het POM.xml-bestand. Het zal alle afhankelijkheden downloaden in je lokale 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>
specificeer ook het profiel 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();
}