在 Eclipse 中构建 Drools 4 项目时出现问题

发布于 2024-08-05 01:38:01 字数 194 浏览 8 评论 0原文

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

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

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

I'm having trouble compiling a drools 4 project. I'm getting errors in the rules file saying

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

The incremental compiler isn't working because of this. How do I fix the errors or get eclipse to ignore them?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

如若梦似彩虹 2024-08-12 01:38:01

drools 3.06 迁移到 4.0.7,那么你使用的 eclipse 和 drools 是什么版本?

这可能与类路径问题有关:

使用调试器我意识到 Drools PackageBuilder 尝试从加载类

Thread.currentThread().getContextClassLoader();

ClassLoader不包含我的代理类!甚至系统类加载器也不包含我的类。

解决方案是:

不必创建普通的 PackageBuilderRuleBase 实例,而是必须使用 PackageBuilderConfigurationRuleBaseConfiguration 创建它们> 两者都配置了当前的classLoader

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());

This issue was mentioned for a migration from drools 3.06 to 4.0.7, so what version of eclipse and drools are you using?

This might be related to a 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.

The solution was:

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());
七颜 2024-08-12 01:38:01

确保您从规则中使用的 MyClassName 或任何其他类位于 jar 文件中,并且该 jar 文件位于类路径中。

Ensure that the MyClassName or any other class(es) that you use from the rule are in a jar file and the jar file is in classpath.

素罗衫 2024-08-12 01:38:01

嗯,我清理了项目并解决了问题。

Hmmm, I cleaned the project and that resolved the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文