无法运行“Hello World” Eclipse 中的 Drools 示例:运行时异常 org.drools.RuntimeDroolsException:无法加载方言

发布于 2024-09-10 21:07:33 字数 2542 浏览 9 评论 0原文

我刚刚在 Eclipse(版本 3.5.2)中安装了 Drools 插件,并且我正在尝试运行该插件附带的“Hello World”示例。

当我运行代码时,我收到运行时错误,并显示以下堆栈跟踪:

org.drools.RuntimeDroolsException: Unable to load dialect 'org.drools.rule.builder.dialect.java.JavaDialectConfiguration:java:org.drools.rule.builder.dialect.java.JavaDialectConfiguration'
 at org.drools.compiler.PackageBuilderConfiguration.addDialect(PackageBuilderConfiguration.java:274)
 at org.drools.compiler.PackageBuilderConfiguration.buildDialectConfigurationMap(PackageBuilderConfiguration.java:259)
 at org.drools.compiler.PackageBuilderConfiguration.init(PackageBuilderConfiguration.java:176)
 at org.drools.compiler.PackageBuilderConfiguration.<init>(PackageBuilderConfiguration.java:153)
 at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:242)
 at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:142)
 at org.drools.builder.impl.KnowledgeBuilderProviderImpl.newKnowledgeBuilder(KnowledgeBuilderProviderImpl.java:29)
 at org.drools.builder.KnowledgeBuilderFactory.newKnowledgeBuilder(KnowledgeBuilderFactory.java:29)
 at com.sample.DroolsTest.readKnowledgeBase(DroolsTest.java:39)
 at com.sample.DroolsTest.main(DroolsTest.java:23)
Caused by: java.lang.RuntimeException: **The Eclipse JDT Core jar is not in the classpath**
 at org.drools.rule.builder.dialect.java.JavaDialectConfiguration.setCompiler(JavaDialectConfiguration.java:94)
 at org.drools.rule.builder.dialect.java.JavaDialectConfiguration.init(JavaDialectConfiguration.java:55)
 at org.drools.compiler.PackageBuilderConfiguration.addDialect(PackageBuilderConfiguration.java:270)
 ... 9 more

以下是一些相关的 Java 代码:

public static final void main(String[] args) {
    try {
        // load up the knowledge base
        KnowledgeBase kbase = readKnowledgeBase();
    }
}

private static KnowledgeBase readKnowledgeBase() throws Exception {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource("Sample.drl"), ResourceType.DRL);
    KnowledgeBuilderErrors errors = kbuilder.getErrors();
    if (errors.size() > 0) {
        for (KnowledgeBuilderError error : errors) {
            System.err.println(error);
        }
        throw new IllegalArgumentException("Could not parse knowledge.");
    }
    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    return kbase;
}

I just installed the Drools plug-in in Eclipse (version 3.5.2), and I am trying to run the "Hello World" example that comes with the plug-in.

When I run the code, I am getting runtime error with the following stack trace:

org.drools.RuntimeDroolsException: Unable to load dialect 'org.drools.rule.builder.dialect.java.JavaDialectConfiguration:java:org.drools.rule.builder.dialect.java.JavaDialectConfiguration'
 at org.drools.compiler.PackageBuilderConfiguration.addDialect(PackageBuilderConfiguration.java:274)
 at org.drools.compiler.PackageBuilderConfiguration.buildDialectConfigurationMap(PackageBuilderConfiguration.java:259)
 at org.drools.compiler.PackageBuilderConfiguration.init(PackageBuilderConfiguration.java:176)
 at org.drools.compiler.PackageBuilderConfiguration.<init>(PackageBuilderConfiguration.java:153)
 at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:242)
 at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:142)
 at org.drools.builder.impl.KnowledgeBuilderProviderImpl.newKnowledgeBuilder(KnowledgeBuilderProviderImpl.java:29)
 at org.drools.builder.KnowledgeBuilderFactory.newKnowledgeBuilder(KnowledgeBuilderFactory.java:29)
 at com.sample.DroolsTest.readKnowledgeBase(DroolsTest.java:39)
 at com.sample.DroolsTest.main(DroolsTest.java:23)
Caused by: java.lang.RuntimeException: **The Eclipse JDT Core jar is not in the classpath**
 at org.drools.rule.builder.dialect.java.JavaDialectConfiguration.setCompiler(JavaDialectConfiguration.java:94)
 at org.drools.rule.builder.dialect.java.JavaDialectConfiguration.init(JavaDialectConfiguration.java:55)
 at org.drools.compiler.PackageBuilderConfiguration.addDialect(PackageBuilderConfiguration.java:270)
 ... 9 more

Here is some of the relevant Java code:

public static final void main(String[] args) {
    try {
        // load up the knowledge base
        KnowledgeBase kbase = readKnowledgeBase();
    }
}

private static KnowledgeBase readKnowledgeBase() throws Exception {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource("Sample.drl"), ResourceType.DRL);
    KnowledgeBuilderErrors errors = kbuilder.getErrors();
    if (errors.size() > 0) {
        for (KnowledgeBuilderError error : errors) {
            System.err.println(error);
        }
        throw new IllegalArgumentException("Could not parse knowledge.");
    }
    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    return kbase;
}

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

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

发布评论

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

评论(6

夏见 2024-09-17 21:07:33

您的类路径中缺少 eclipse JDT core jar。如果您没有使用 Drools 类路径容器或者您手动创建了自己的运行时,请确保该 jar 是您的类路径或运行时目录的一部分。如果您使用 Drools 类路径容器并生成默认运行时,并且 JDT 核心 jar 不存在,请确保使用支持 Eclipse 3.5.2 的最新版本的插件。当然,您也可以手动添加 JDT 核心 jar 并重新创建运行时。

有关运行时的更多信息,请访问 http://download.jboss.org/drools/release/5.1.1.34858.FINAL/drools-5.1.1-docs.zip 并打开 drools-5.1.1-docs.zip\drools -flow\html\ch.Drools_Eclipse_IDE_Features.html

You're missing the eclipse JDT core jar in your classpath. If you are not using the Drools classpath container or if you manually created your own runtime, make sure that jar is part of your classpath or runtime directory. If you are using the Drools classpath container and generated a default runtime, and the JDT core jar is not there, make sure to use a recent version of the plugin that supports Eclipse 3.5.2. You can of course also just add the JDT core jar manually and recreate your runtime.

More info on runtimes can be found at http://download.jboss.org/drools/release/5.1.1.34858.FINAL/drools-5.1.1-docs.zip and open up drools-5.1.1-docs.zip\drools-flow\html\ch.Drools_Eclipse_IDE_Features.html

我只土不豪 2024-09-17 21:07:33

如果您使用的是 JDK 1.7 或更高版本,则需要在创建 JVM 之前设置参数,因为 JNI4NET Sample 上使用的 Drools 是版本 5.1,它不适用于 JDK 1.7 或更高版本。

在创建 JVM 之前尝试使用此行:

var bridgeSetup = new BridgeSetup();
// ... 
bridgeSetup.AddJVMOption("-Ddrools.dialect.java.compiler.lnglevel", "1.6");
// ...
Bridge.CreateJVM(bridgeSetup);

If you are using a JDK 1.7 or over, you will have set a parameter before create JVM because Drools used on JNI4NET Sample is version 5.1 and it doesn't work on JDK 1.7 or over.

Try use this line before create JVM:

var bridgeSetup = new BridgeSetup();
// ... 
bridgeSetup.AddJVMOption("-Ddrools.dialect.java.compiler.lnglevel", "1.6");
// ...
Bridge.CreateJVM(bridgeSetup);
草莓味的萝莉 2024-09-17 21:07:33

这是一个常见问题,只需在类路径中包含 eclipse Jdt core jar 即可解决此问题。
您可以从这里添加 jar:
http://www.java2s.com/Code/Jar/o/Downloadorgeclipsejdtcore371jar。嗯

This is a common problem,just include eclipse Jdt core jar in your class path ,it will solve this problem.
You can add jar from here:
http://www.java2s.com/Code/Jar/o/Downloadorgeclipsejdtcore371jar.htm

风柔一江水 2024-09-17 21:07:33

所以我终于重新开始了。

我执行了以下操作(2014 年 4 月)

  1. 从 Eclipse Kepler 的全新安装开始
  2. 转到 Eclipse Marketplace 并搜索“JBoss Developer Studio (Kepler)”,然后安装:“Red Hat JBoss Developer Studio (Kepler) 7.1.1.GA” (您的版本可能有所不同)
  3. 重新启动 Eclipse
  4. 转到 Eclipse Marketplace 并搜索“JBoss Developer Studio (Kepler)”,然后安装:“JBoss Tools (Kepler) 4.1.2.Final”(您的版本可能有所不同)
  5. 重新启动 Eclipse。
  6. 安装“流口水”。转到 Eclipse 菜单,然后选择“帮助”/“安装新软件”并添加以下 URL。
    Drools_UpdateSite - http://download.jboss.org/ drools/release/6.0.0.Final/org.drools.updatesite/
    我安装了每个选项。
  7. 重新启动 Eclipse。
  8. 转到 New-Project 并添加一个新的“Drools Project”。

然后我就可以运行流口水的“hello world”了。

我还添加了:

转到 Eclipse 菜单,然后“帮助”/“安装新软件”并添加以下 URL。

http://download.eclipse.org/technology/m2e/releases 

并安装了

"m2e - Maven Integration for Eclipse"
and "m2e - slf4j over logback logging (Optional)"

So I finally started over.

I did the following (April, 2014)

  1. Starting with clean install of Eclipse Kepler
  2. Go to Eclipse Marketplace and search for "JBoss Developer Studio (Kepler)" and then install: "Red Hat JBoss Developer Studio (Kepler) 7.1.1.GA" (Your version may vary)
  3. Restart Eclipse
  4. Go to Eclipse Marketplace and search for "JBoss Developer Studio (Kepler)" and then install: "JBoss Tools (Kepler) 4.1.2.Final" (Your version may vary)
  5. Restart Eclipse.
  6. Install "drools". Go to Eclipse Menu and then "Help" / "Install New Software" and add the below URL.
    Drools_UpdateSite - http://download.jboss.org/drools/release/6.0.0.Final/org.drools.updatesite/
    I installed every option.
  7. Restart Eclipse.
  8. Go to New-Project and add a new "Drools Project".

Then I was able to run the drools "hello world".

I also added:

Go to Eclipse Menu and then "Help" / "Install New Software" and add the below URL.

http://download.eclipse.org/technology/m2e/releases 

and installed

"m2e - Maven Integration for Eclipse"
and "m2e - slf4j over logback logging (Optional)"
余厌 2024-09-17 21:07:33

我遇到了同样的问题。
正如其他答案中所述,如果运行时是手动创建的(如我的情况),那么您需要在类路径中添加 eclipse JDT core jar。
这是 jar 的下载链接-> http://www.java2s.com/Code/Jar/o/Downloadorgeclipsejdtcore371jar.htm
将其添加到类路径解决了我的问题。

I faced the same problem.
As stated in other answers that if runtime is created manually(as in my case) then you need to add the eclipse JDT core jar in your classpath.
here is the download link for the jar-> http://www.java2s.com/Code/Jar/o/Downloadorgeclipsejdtcore371jar.htm
Adding this to the classpath solved my problem.

红颜悴 2024-09-17 21:07:33

http://www.java2s.com/Code/Jar/o/Downloadorgeclipsejdtcore371jar。 htm eclipse JDT core jar 在你的类路径中。

输入图片这里的描述

请确保它应该是一个 jar 文件而不是 zip 文件。

http://www.java2s.com/Code/Jar/o/Downloadorgeclipsejdtcore371jar.htm eclipse JDT core jar in your classpath.

enter image description here

Please ensure it should be a jar not zip file.

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