gpt4 book ai didi

java - 在 Eclipse 中构建 Drools 4 项目的问题

转载 作者:行者123 更新时间:2023-11-30 09:57:52 25 4
gpt4 key购买 nike

我在编译 drools 4 项目时遇到问题。我在规则文件中收到错误

Only a type can be imported. <<MyClassName>> resolves to a package 

增量编译器因此无法工作。如何修复错误或让 Eclipse 忽略它们?

最佳答案

drools 3.06 to 4.0.7 迁移时提到了这个问题,那么您使用的是什么版本的 eclipse 和 drools?

这可能与 classpath issue 有关:

Using the debugger I realized that the Drools PackageBuilder tried to load the classes from the

Thread.currentThread().getContextClassLoader();

This ClassLoader does not contain my agent classes! Even the system class loader does not contain my classes.

解决方案是:

Instead of creating plain PackageBuilder and RuleBase instances, one has to create them with a PackageBuilderConfiguration and a RuleBaseConfiguration both with the current classLoader configured:

ClassLoader classLoader = this.getClass().getClassLoader();

PackageBuilderConfiguration configuration = new PackageBuilderConfiguration();
configuration.setClassLoader(classLoader);

PackageBuilder builder = new PackageBuilder(configuration);

builder.addPackageFromDrl(source);

RuleBaseConfiguration ruleBaseConfiguration = new RuleBaseConfiguration();
ruleBaseConfiguration.setClassLoader(classLoader);

ruleBase = RuleBaseFactory.newRuleBase(ruleBaseConfiguration);
ruleBase.addPackage(builder.getPackage());

关于java - 在 Eclipse 中构建 Drools 4 项目的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1398532/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com