aspose file tools*
The moose likes JBoss/WildFly and the fly likes What is JBoss Drools? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "What is JBoss Drools?" Watch "What is JBoss Drools?" New topic
Author

What is JBoss Drools?

paresh doshi
Ranch Hand

Joined: Nov 20, 2006
Posts: 81
Hi,

I have got a project on jboss Drools. Can anyone provide some details or some sample examples how it works. I am totally new to this.

Thanks in advance.


Thanks.<br />Paresh Doshi<br />SCJP 1.4
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10290
    
168

Drools (also known as JBoss Rules) is an open source Rules Engine. You can find more information including documentation here


[My Blog] [JavaRanch Journal]
paresh doshi
Ranch Hand

Joined: Nov 20, 2006
Posts: 81
Hi I made the sample code with the sample drl file. Test.xml as belows

<?xml version="1.0"?>
<rule-set name="Bottles song"
xmlns="http://drools.org/rules"
xmlns:java="http://drools.org/semantics/java"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://drools.org/rules rules.xsd
http://drools.org/semantics/java java.xsd">


<rule name="FlagAsUndervalued">
<parameter identifier="person">
<java:class>com.sample.Person</java:class>
</parameter>
<java:condition>person.getAge()>18</java:condition>

<java:consequence>
System.out.println("Hello");
</java:consequence>
</rule>
</rule-set>


I have written the following code to fire the jboss rules.

package com.sample;
import java.net.URL;
import java.io.*;
import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.WorkingMemory;
import org.drools.compiler.PackageBuilder;
import org.drools.io.RuleBaseLoader;
import org.xml.sax.*;
public class TestDrules {
private static RuleBase rules;
public static URL ruleSource = TestDrules.class.getResource("Test.xml");
public static void main(String[] args) throws Exception{





PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl(new InputStreamReader(TestDrules.class.getResourceAsStream("Test.xml")));
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage(builder.getPackage());
WorkingMemory workingMemory = ruleBase.newStatefulSession();
Person p = new Person();
p.setAge(99);
p.setStrName("Avadhut");
workingMemory.insert(p);
workingMemory.fireAllRules();


}



}


When i run the code I get the following error.

org.drools.compiler.PackageBuilder$MissingPackageNameException: Missing package name for rule package.
at org.drools.compiler.PackageBuilder.validatePackageName(PackageBuilder.java:320)
at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:236)
at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:167)
at com.sample.TestDrules.main(TestDrules.java:27)



Can anyone please help me out.
Thanks in advance.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is JBoss Drools?