Java 无法在 Eclipse 中运行“Hello World”Drools 示例:运行时异常 org.drools.RuntimeDroolsException:无法加载方言
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3295744/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to run "Hello World" Drools example in Eclipse: runtime exception org.drools.RuntimeDroolsException: Unable to load dialect
提问by user396377
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.
我刚刚Drools plug-in
在 Eclipse(3.5.2 版)中安装了,我正在尝试运行插件附带的“Hello World”示例。
When I run the code, I am getting runtime error
with the following stack trace:
当我运行代码时,我得到runtime error
以下堆栈跟踪:
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:
下面是一些相关的 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;
}
回答by Kris Verlaenen
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.
您的类路径中缺少 eclipse JDT 核心 jar。如果您没有使用 Drools 类路径容器,或者您手动创建了自己的运行时,请确保该 jar 是您的类路径或运行时目录的一部分。如果您使用 Drools 类路径容器并生成默认运行时,并且 JDT 核心 jar 不在那里,请确保使用支持 Eclipse 3.5.2 的插件的最新版本。您当然也可以手动添加 JDT 核心 jar 并重新创建您的运行时。
More info on runtimes can be found at http://download.jboss.org/drools/release/5.1.1.34858.FINAL/drools-5.1.1-docs.zipand open up drools-5.1.1-docs.zip\drools-flow\html\ch.Drools_Eclipse_IDE_Features.html
有关运行时的更多信息,请访问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
回答by Phelipe Perbtheitroades
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.
如果您使用的是 JDK 1.7 或更高版本,则您将在创建 JVM 之前设置一个参数,因为在 JNI4NET Sample 上使用的 Drools 是 5.1 版,它不适用于 JDK 1.7 或更高版本。
Try use this line before create JVM:
在创建 JVM 之前尝试使用此行:
var bridgeSetup = new BridgeSetup();
// ...
bridgeSetup.AddJVMOption("-Ddrools.dialect.java.compiler.lnglevel", "1.6");
// ...
Bridge.CreateJVM(bridgeSetup);
回答by granadaCoder
So I finally started over.
所以我终于重新开始了。
I did the following (April, 2014)
我做了以下事情(2014 年 4 月)
- Starting with clean install of Eclipse Kepler
- 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)
- Restart Eclipse
- 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)
- Restart Eclipse.
- 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.
- Restart Eclipse.
- Go to New-Project and add a new "Drools Project".
- 从全新安装 Eclipse Kepler 开始
- 前往 Eclipse Marketplace 并搜索“JBoss Developer Studio (Kepler)”,然后安装:“Red Hat JBoss Developer Studio (Kepler) 7.1.1.GA”(您的版本可能有所不同)
- 重启 Eclipse
- 前往 Eclipse Marketplace 并搜索“JBoss Developer Studio (Kepler)”,然后安装:“JBoss Tools (Kepler) 4.1.2.Final”(您的版本可能有所不同)
- 重新启动 Eclipse。
- 安装“流口水”。转到 Eclipse 菜单,然后“帮助”/“安装新软件”并添加以下 URL。Drools_UpdateSite - http://download.jboss.org/drools/release/6.0.0.Final/org.drools.updatesite/我安装了每个选项。
- 重新启动 Eclipse。
- 转到新建项目并添加一个新的“Drools 项目”。
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.
转到 Eclipse 菜单,然后“帮助”/“安装新软件”并添加以下 URL。
http://download.eclipse.org/technology/m2e/releases
and installed
并安装
"m2e - Maven Integration for Eclipse"
and "m2e - slf4j over logback logging (Optional)"
回答by Yatin
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.htmAdding this to the classpath solved my problem.
我遇到了同样的问题。正如其他答案中所述,如果运行时是手动创建的(如我的情况),那么您需要在类路径中添加 eclipse JDT 核心 jar。这是 jar 的下载链接-> http://www.java2s.com/Code/Jar/o/Downloadorgeclipsejdtcore371jar.htm将此添加到类路径解决了我的问题。
回答by jeenat parihar
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
这是一个常见问题,只需在您的类路径中包含 eclipse Jdt 核心 jar,它就会解决这个问题。您可以从这里添加 jar:http: //www.java2s.com/Code/Jar/o/Downloadorgeclipsejdtcore371jar.htm
回答by Lalchand Mali
http://www.java2s.com/Code/Jar/o/Downloadorgeclipsejdtcore371jar.htmeclipse JDT core jar in your classpath.
http://www.java2s.com/Code/Jar/o/Downloadorgeclipsejdtcore371jar.htmeclipse JDT 核心 jar 在您的类路径中。
Please ensure it should be a jar not zip file.
请确保它应该是一个 jar 而不是 zip 文件。