为什么缓存的 Drools KIE 基础仍然需要源 .drl 文件?

Why cached Drools KIE bases still require source .drl files?

谁能解释一下,为什么 Drools 引擎仍然需要源 .drl 文件,即使已经使用 kie-maven-plugin 创建和部署了缓存的预编译 KIE 库?是否可以只使用预编译的缓存文件? 我们正在使用 Drools 6.2.0.Final 和 kie-maven-plugin 来创建预编译的 KIE 基础。生成的 .jar 文件包含每个 KIE 基础的二进制 kbase.cache 文件和相应的 .drl 源文件。如果我们尝试从生成的 .jar 中删除源 .drl 文件,KIE 基础加载失败。 我们的 KIE 基地有 6000 多条规则。这就是加载所有 KIE 库的时间很重要的原因。在 "kieContainer.getKieBase("kie base name")" 调用期间,Drools 引擎花费相当多的时间来加载缓存的 KIE base 和源 .drl 文件。这就是为什么删除 .drl 文件将使我们能够更快地加载 KIE 库。为什么我们仍然需要保留源 .drl 文件?谢谢。

一个简单的方法是编译DRL文件,序列化生成的KieBase,把文件放在你想要的地方。然后,只需反序列化并创建您的会话,然后就可以了。

第一部分:

KieServices kieServices = KieServices.Factory.get();
KieFileSystem kfs = kieServices.newKieFileSystem();

/*** repeat
FileInputStream fis = new FileInputStream( "simple/simple.drl" );
kfs.write( "src/main/resources/simple.drl",
           kieServices.getResources().newInputStreamResource( fis ) );
/** until exhausted **/

KieBuilder kieBuilder = kieServices.newKieBuilder( kfs ).buildAll();
Results results = kieBuilder.getResults();
if( results.hasMessages( Message.Level.ERROR ) ){
    System.out.println( results.getMessages() );
    throw new IllegalStateException( "### errors ###" );
}

KieContainer kieContainer =
    kieServices.newKieContainer( kieServices.getRepository().getDefaultReleaseId() );
KieBase kieBase = kieContainer.getKieBase();

FileOutputStream fos = new FileOutputStream( BASEPATH );
ObjectOutputStream oos = new ObjectOutputStream( fos );
oos.writeObject( kieBase );
oos.close();

第二部分:

FileInputStream fis = new FileInputStream( BASEPATH );
ObjectInputStream ois = new ObjectInputStream( fis );
KieBase kieBase = (KieBase)ois.readObject();
kieSession = kieBase1.newKieSession();

我已收到 KIE 开发团队负责人的答复: "The cache is for the .class compilations. It still needs the DRL to build the rules and wire the pre-compiled .class files. It’s done this way as in general the parser and rule builders not too intensive, but .class generation is." https://groups.google.com/forum/#!topic/drools-usage/XqzfBvpdjSg 谢谢。