本文介绍了PackageBuilder.java在Drools 6.1.0.final中不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Drools的新手,我们目前在我们的项目中使用Drools 5.4.0.当前,我们正在使用Drools 5.4.0的RuleCompiler.java和PackageBuilder.java类来编译.xls文件并创建ruleSetObject.代码段如下所示

I am new to drools and we are currently using Drools 5.4.0 in our project.Currently we are using RuleCompiler.java and PackageBuilder.java classes of Drools 5.4.0 to compile the .xls files and create ruleSetObject. The code snippet is as given below

String drlFromFile = null;
if (Pattern.matches(regexPattern, file.getName())) {
    if (file.getName().contains("csv") || file.getName().contains("CSV")) {
        drlFromFile = RuleCompiler.compileCSV(file);
    } else {
        drlFromFile = RuleCompiler.compileSpreadSheet(file);
    }
    if (drlFromFile == null || drlFromFile.isEmpty()) {
        logger.debug("Unable to Compile Rule Sheet: " + file.getName());
        throw new DroolsParserException("Unable to Compile Rule Sheet: " + file.getName());
    }
    PackageBuilder builder = new PackageBuilder();
    builder.addPackageFromDrl(new StringReader(drlFromFile));
    Package ruleSetObject = builder.getPackage();

    // Registering the compiled drl object in ruleExecutionSetRegistry
    ruleExecutionSetRegistry.registerRuleSetObject(file.getName(), ruleSetObject,
                    getRuleEngineProviderName());
}

现在我们需要升级到Drools 6.1.0.final,但是我在那里找不到PackageBuilder.java类.我试图寻找它的替代品,但没有得到任何东西.

Now we need to upgrade to Drools 6.1.0.final, but I can not find the PackageBuilder.java class there. I tried to search for its replacement but didn't get anything.

是否已引入任何新类来代替PackageBuilder.java?有没有人指导我如何使用该课程?

Is any new class has been introduced in place of PackageBuilder.java? Does any one guide me how to use that class?

推荐答案

做事的新"方法是定义一个 KieModule .本质上,您将创建一个包装了Drools规则的Maven项目,然后将该项目添加为运行时的依赖项.通常,这希望您遵循某些约定说明如何构造项目,以便Drools可以自己找到规则.

The 'new' way to do things is by defining a KieModule. Essentially, you create a Maven project which wraps your Drools rules, and then add that project as a dependency for your runtime. Generally, this expects that you will follow certain conventions in how you structure your project so that Drools can find your rules itself.

但是,您(与我一样)可能会发现,在不完全重组现有项目的情况下,更容易进行迁移.为此,您仍然可以通过将文件添加到 KieFileSystem 中来构建 KieService (新的 KnowledgeBase ).这是一个粗略的例子:

However, you may (like me) find it easier to migrate without completely restructuring your existing project. To achieve this, you can still build up a KieService (the new KnowledgeBase), by adding files to a KieFileSystem. Here's a rough example of doing that:

KieServices kieServices = KieServices.Factory.get();

KieFileSystem kfs = kieServices.newKieFileSystem();
kfs.write(ResourceFactory.newFileResource(resource.getPath()));

KieBuilder kieBuilder = kieServices.newKieBuilder(kfs).buildAll();
if (kieBuilder.getResults().hasMessages(Level.ERROR)) {
    // It didn't build. Do something about it...
}

KieContainer kieContainer = kieServices
        .newKieContainer(kieServices.getRepository().getDefaultReleaseId());

KieSession kieSession = kieContainer.newKieSession();

您已经准备好出发了.如果有用,我最近的一个演示项目包含针对纯.drl文件执行此操作的示例,据我了解,如果要将电子表格添加到 KieFileSystem 而不是DRL.

And you're pretty much ready to go. In case it's useful, a recent demo project of mine contains an example of doing this for plain .drl files, and from what I understand, it should be pretty much the same if you want to add a spreadsheet to the KieFileSystem instead of DRL.

这篇关于PackageBuilder.java在Drools 6.1.0.final中不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 02:03