Dear all,
Please help me out in this...
MyDrools.java import java.io.*;
import org.drools.compiler.*;
import org.drools.*;
import org.drools.rule.Package;
import org.drools.rule.builder.dialect.java.JavaDialectConfiguration;
public class MyDrools{
public void initRuleBase(){
Reader source = new InputStreamReader( MyDrools.class.getResourceAsStream( "MyRule.drl" ) );
JavaDialectConfiguration javaDialectConf=new JavaDialectConfiguration();
javaDialectConf.setCompiler(JavaDialectConfiguration.JANINO);
javaDialectConf.setJavaLanguageLevel("1.5");
PackageBuilderConfiguration conf=javaDialectConf.getPackageBuilderConfiguration();
PackageBuilder builder=new PackageBuilder(conf);
try{
//this wil parse and compile in one step
builder.addPackageFromDrl( source );
// Check the builder for errors
if ( builder.hasErrors() ) {
System.out.println( builder.getErrors().toString() );
throw new RuntimeException( "Unable to compile \"MyRule.drl\".");
}
//get the compiled package (which is serializable)
Package pkg = builder.getPackage();
//add the package to a rulebase (deploy the rule package).
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage( pkg );
StatefulSession session = ruleBase.newStatefulSession();
session.insert( new Bob() );
session.fireAllRules();
}catch(Exception e){
e.printStackTrace();
}
}
public static void main(
String a[]){
new MyDrools().initRuleBase();
}
}
Bob.java public class Bob{
public String name="";
public void setName(String name){
this.name=name;
}
public String getName(){
return name;
}
public boolean likesCheese(){
return true;
}
}
MyRule.drl package rules;
rule "bob likes cheese"
when
bob: Bob(1==1)
then
System.out.println("hi");
end
This compiles successfully but I am getting this at Runtime... I am using the Drools 4.0.7 jars...
Exception in
thread "main" org.drools.RuntimeDroolsException: Unable to load dialect 'org.drools.rul
e.builder.dialect.java.JavaDialectConfiguration:java'
at org.drools.compiler.PackageBuilderConfiguration.addDialect(PackageBuilderConfiguration.ja
va:160)
at org.drools.compiler.PackageBuilderConfiguration.buildDialectConfigurationMap(PackageBuild
erConfiguration.java:146)
at org.drools.compiler.PackageBuilderConfiguration.init(PackageBuilderConfiguration.java:121
)
at org.drools.compiler.PackageBuilderConfiguration.<init>(PackageBuilderConfiguration.java:9
8)
at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:124)
at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:108)
at MyDrools.initRuleBase(MyDrools.java:18)
at MyDrools.main(MyDrools.java:50)
Caused by: java.lang.RuntimeException: The Eclipse JDT Core jar is not in the classpath
at org.drools.rule.builder.dialect.java.JavaDialectConfiguration.setCompiler(JavaDialectConf
iguration.java:91)
at org.drools.rule.builder.dialect.java.JavaDialectConfiguration.init(JavaDialectConfigurati
on.java:52)
at org.drools.compiler.PackageBuilderConfiguration.addDialect(PackageBuilderConfiguration.ja
va:156)
... 7 more
Can someone help me out with this?
John