无法运行“Hello World” Eclipse 中的 Drools 示例:运行时异常 org.drools.RuntimeDroolsException:无法加载方言
我刚刚在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您的类路径中缺少 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
如果您使用的是 JDK 1.7 或更高版本,则需要在创建 JVM 之前设置参数,因为 JNI4NET Sample 上使用的 Drools 是版本 5.1,它不适用于 JDK 1.7 或更高版本。
在创建 JVM 之前尝试使用此行:
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:
这是一个常见问题,只需在类路径中包含 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
所以我终于重新开始了。
我执行了以下操作(2014 年 4 月)
Drools_UpdateSite - http://download.jboss.org/ drools/release/6.0.0.Final/org.drools.updatesite/
我安装了每个选项。
然后我就可以运行流口水的“hello world”了。
我还添加了:
转到 Eclipse 菜单,然后“帮助”/“安装新软件”并添加以下 URL。
并安装了
So I finally started over.
I did the following (April, 2014)
Drools_UpdateSite - http://download.jboss.org/drools/release/6.0.0.Final/org.drools.updatesite/
I installed every option.
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.
and installed
我遇到了同样的问题。
正如其他答案中所述,如果运行时是手动创建的(如我的情况),那么您需要在类路径中添加 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.
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.
Please ensure it should be a jar not zip file.