使用 Maven 的 Drools 决策表预编译
Drools decision tables precompilation using Maven
根据 drools 6.3 documentation, section 4.2.2.3 :
The KIE plugin for Maven ensures that artifact resources are validated and pre-compiled, it is recommended that this is used at all times. To use the plugin simply add it to the build section of the Maven pom.xml
因此,我的 pom.xml 是:
<dependencies>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-compiler</artifactId>
<version>6.3.0.Final-redhat-9</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-decisiontables</artifactId>
<version>6.3.0.Final-redhat-9</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.kie</groupId>
<artifactId>kie-maven-plugin</artifactId>
<version>6.3.0.Final-redhat-9</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
我将我的决定 table 文件放在了 src/main/resources/my/company/package/
中,我们称它为 rules.xls
。我的 Maven 项目中唯一的另一个文件是 kmodule.xml
文件,它位于 src/main/resources/META-INF/
中并包含最少的代码:
<?xml version="1.0" encoding="UTF-8"?>
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule"/>
因为我删除了所有其他依赖项(包括包含决策 table 中使用的 Java 对象的依赖项),我希望 drools 启动类型为 [=17 的错误消息=].
但是当我尝试使用 Maven clean install
项目时,编译成功,创建了一个 JAR 文件,它确实在确切位置包含 kmodule.xml
和 rules.xls
文件我把它们放在哪里。编译期间没有生成额外的文件,没有错误,没有警告,什么都没有。只是一个包含我的文件的普通 JAR,一个 MANIFEST.MF
文件和 META-INF
.
下的一个 maven
目录
在 Maven 跟踪中,这里是激活的插件(按此顺序):
[INFO] --- maven-clean-plugin:2.4.1:clean
[INFO] --- maven-resources-plugin:2.5:resources
[INFO] --- maven-compiler-plugin:2.3.2:compile
[INFO] --- maven-resources-plugin:2.5:testResources
[INFO] --- maven-compiler-plugin:2.3.2:testCompile
[INFO] --- maven-surefire-plugin:2.10:test
[INFO] --- maven-jar-plugin:2.3.2:jar
[INFO] --- maven-install-plugin:2.3.1:install
没有关于 kie 插件的信息。在构建时激活规则编译的任何提示?
为了激活 kie-maven-plugin,还需要在 pom.xml
中指定正确的包装类型
<packaging>kjar</packaging>
我终于找到激活插件的方法了。我将此添加到我的 pom.xml 中:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.kie</groupId>
<artifactId>kie-maven-plugin</artifactId>
<version>6.3.0.Final-redhat-9</version>
<extensions>true</extensions>
<executions>
<execution>
<id>brms-rules-compilation</id>
<phase>generate-resources</phase>
<goals>
<goal>build</goal>
</goals>
<inherited>false</inherited>
<configuration>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
现在获取 Drools 编译跟踪,包括:
[INFO] --- kie-maven-plugin:6.3.0.Final-redhat-9:build
[main] INFO org.drools.compiler.kie.builder.impl.KieRepositoryImpl - Adding KieModule from resource: FileResource[...]
我不是 Maven 高手,这个解决方案可能不是最好的(我什至不完全理解我写的 Maven 透视图),所以我很乐意得到一个更简单的解决方案。
根据 drools 6.3 documentation, section 4.2.2.3 :
The KIE plugin for Maven ensures that artifact resources are validated and pre-compiled, it is recommended that this is used at all times. To use the plugin simply add it to the build section of the Maven pom.xml
因此,我的 pom.xml 是:
<dependencies>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-compiler</artifactId>
<version>6.3.0.Final-redhat-9</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-decisiontables</artifactId>
<version>6.3.0.Final-redhat-9</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.kie</groupId>
<artifactId>kie-maven-plugin</artifactId>
<version>6.3.0.Final-redhat-9</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
我将我的决定 table 文件放在了 src/main/resources/my/company/package/
中,我们称它为 rules.xls
。我的 Maven 项目中唯一的另一个文件是 kmodule.xml
文件,它位于 src/main/resources/META-INF/
中并包含最少的代码:
<?xml version="1.0" encoding="UTF-8"?>
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule"/>
因为我删除了所有其他依赖项(包括包含决策 table 中使用的 Java 对象的依赖项),我希望 drools 启动类型为 [=17 的错误消息=].
但是当我尝试使用 Maven clean install
项目时,编译成功,创建了一个 JAR 文件,它确实在确切位置包含 kmodule.xml
和 rules.xls
文件我把它们放在哪里。编译期间没有生成额外的文件,没有错误,没有警告,什么都没有。只是一个包含我的文件的普通 JAR,一个 MANIFEST.MF
文件和 META-INF
.
maven
目录
在 Maven 跟踪中,这里是激活的插件(按此顺序):
[INFO] --- maven-clean-plugin:2.4.1:clean
[INFO] --- maven-resources-plugin:2.5:resources
[INFO] --- maven-compiler-plugin:2.3.2:compile
[INFO] --- maven-resources-plugin:2.5:testResources
[INFO] --- maven-compiler-plugin:2.3.2:testCompile
[INFO] --- maven-surefire-plugin:2.10:test
[INFO] --- maven-jar-plugin:2.3.2:jar
[INFO] --- maven-install-plugin:2.3.1:install
没有关于 kie 插件的信息。在构建时激活规则编译的任何提示?
为了激活 kie-maven-plugin,还需要在 pom.xml
中指定正确的包装类型<packaging>kjar</packaging>
我终于找到激活插件的方法了。我将此添加到我的 pom.xml 中:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.kie</groupId>
<artifactId>kie-maven-plugin</artifactId>
<version>6.3.0.Final-redhat-9</version>
<extensions>true</extensions>
<executions>
<execution>
<id>brms-rules-compilation</id>
<phase>generate-resources</phase>
<goals>
<goal>build</goal>
</goals>
<inherited>false</inherited>
<configuration>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
现在获取 Drools 编译跟踪,包括:
[INFO] --- kie-maven-plugin:6.3.0.Final-redhat-9:build
[main] INFO org.drools.compiler.kie.builder.impl.KieRepositoryImpl - Adding KieModule from resource: FileResource[...]
我不是 Maven 高手,这个解决方案可能不是最好的(我什至不完全理解我写的 Maven 透视图),所以我很乐意得到一个更简单的解决方案。