Unable to run "Hello World" Drools example in Eclipse: runtime exception org.drools.RuntimeDroolsException: Unable to load dialect
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.newKnowledgeBuil开发者_C百科der();
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;
}
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
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);
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
So I finally started over.
I did the following (April, 2014)
- 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".
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)"
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 in your classpath.
Please ensure it should be a jar not zip file.
精彩评论