jQuery in Action, 3rd edition
The moose likes Other Java Products and Servers and the fly likes Drools 4 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Java Products and Servers
Bookmark "Drools 4" Watch "Drools 4" New topic

Drools 4

John Louis

Joined: Aug 14, 2008
Posts: 10
Dear Ranchers,
I have been reading up on Drools 4 and am a complete newbie to the concept. I have chanced upon quite a lot of examples, but unfortunately all depend on Eclipse to set up a Drools project. I downloaded the Drools4 dependencies, the jar files, and tried a standalone java program, a simple hello world, the one that was running with amazing success in eclipse, but I am unable to replicate the same success here.
In most of the examples, they use a rather simple mechanism of creating a RuleBase and that would be:
Reader source=new InputStreamReader(this.Class.getResourceAsReader('MyDrl.drl'));

PackageBuilder p=new PackageBuilder();
This throws a null pointer exception when run outside eclipse.

And the same appln seems to throw an error parsing the drl file too. Is there a difference in the ways I need to confront Drools with and without eclipse?

I'm still trying to build an independent appln. After that my next attempt would be to integrate that to Spring.

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42958
Welcome to JavaRanch.

Is the file MyDrl.drl in the classpath when you run the code? That's where getResourceAsReader would be looking for it (as opposed to the current directory, where file I/O classes would look).
John Louis

Joined: Aug 14, 2008
Posts: 10
Hi again,
At the moment I seem to be stuck with the

PackageBuilder p=new PackageBuilder();
new InputStreamReader(
MyDrools.class.getResourceAsStream( "MyDrl.drl" )

throwing a NullPointerException. I had somehow worked around this problem at work to find p.hasErrors() returning true. I am trying to replicate that problem now.
John Louis

Joined: Aug 14, 2008
Posts: 10
Dear all,
Please help me out in this...

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();

PackageBuilderConfiguration conf=javaDialectConf.getPackageBuilderConfiguration();

PackageBuilder builder=new PackageBuilder(conf);

//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() );

}catch(Exception e){


public static void main(String a[]){
new MyDrools().initRuleBase();

public class Bob{
public String name="";

public void setName(String name){
public String getName(){
return name;

public boolean likesCheese(){
return true;


package rules;

rule "bob likes cheese"
bob: Bob(1==1)

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
at org.drools.compiler.PackageBuilderConfiguration.addDialect(PackageBuilderConfiguration.ja
at org.drools.compiler.PackageBuilderConfiguration.buildDialectConfigurationMap(PackageBuild
at org.drools.compiler.PackageBuilderConfiguration.init(PackageBuilderConfiguration.java:121
at org.drools.compiler.PackageBuilderConfiguration.<init>(PackageBuilderConfiguration.java:9
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
at org.drools.rule.builder.dialect.java.JavaDialectConfiguration.init(JavaDialectConfigurati
at org.drools.compiler.PackageBuilderConfiguration.addDialect(PackageBuilderConfiguration.ja
... 7 more

Can someone help me out with this?

Jaikiran Pai

Joined: Jul 20, 2005
Posts: 10441

Caused by: java.lang.RuntimeException: The Eclipse JDT Core jar is not in the classpath

You probably are missing some jar file in the classpath.

[My Blog] [JavaRanch Journal]
Jaikiran Pai

Joined: Jul 20, 2005
Posts: 10441

Just found this in the drools user mailing list. It suggests, changing the initialization code to:

John Louis

Joined: Aug 14, 2008
Posts: 10
Actually I am trying to run this outside eclipse and it's asking me to include the eclipse JDT core jar files too...

I found the code above too and have written the code I posted based on that (and many others ).
I agree. Here's the link: http://aspose.com/file-tools
subject: Drools 4
It's not a secret anymore!