我有一个流口水6工作台。我试图从工作台读取规则并在独立的Java应用程序中执行它们。有没有办法使用工作台中的URL下载drl文件。请编写代码以及我是drools的新手
答案 0 :(得分:0)
首先创建Java应用程序,包括所有基于drools 6的二进制依赖项。为此,您可以创建Maven驱动的Java应用程序。 在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();
}
答案 1 :(得分:0)
你的pom.xml应该有这些依赖
<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>
或你的classpath文件应该有这些jar
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
滴料的模板-6.0.0.Final.jar
SLF4J-API-1.7.5.jar
Drools的编译器,6.0.0.Final.jar
mvel2-2.1.7.Final.jar
ANTLR运行时,3.5.jar
POI-OOXML-3.9.jar
POI-3.10-beta2.jar
公地郎2.4.jar
西河-1.4.3.jar
的protobuf-java的2.5.0.jar
org.eclipse.jdt.core-3.7.1.jar