You are using old API. Which version of drools are you using?
You need to do something like:
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newXXXResource(YYY); , ResourceType.DRL);
//replace XXX for the type of resource you want
//add all your resources
//check for errors
if (kbuilder.hasEsrrors()){
...
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
I'm pretty sure all this steps are currently described in the
documentation.
Best Regards,
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Esteban Aliverti
- Developer @
http://www.plugtree.com
- Blog @
http://ilesteban.wordpress.com
On Thu, Jan 12, 2012 at 1:37 PM, srinivasasanda <srinivasasanda(a)gmail.com>wrote:
Hi
I wrote code for creating RuleBase. But I got error at retrieving URL
resource by passing ruleFile to the getResource() method.It is returning
null. How to get the URL resource. I posted the sample code which i have
written for creating RuleBase.
public RuleBase createRuleBase() throws Exception
{
if(rules==null)
{
throw new Exception("No rules provided for Engine");
}
ruleBase = RuleBaseFactory.newRuleBase();
PackageBuilder builder = new PackageBuilder();
for(String ruleFile : rules)
{
System.out.println("Rule is "+ruleFile); //prints
the ruleFile
URL resource =
this.getClass().getResource(ruleFile); //gets the URL
resource of the ruleFile
if(resource==null)
{
System.err.println("Could not find
resource: "+ruleFile);
continue;
}
File file = new
File(this.getClass().getResource(ruleFile).getPath());
if(!file.exists())
{
System.err.println("Could not find rule
file: "+file.getPath());
continue;
}
builder.addPackageFromDrl(new
FileReader(file.getPath()));
}
org.drools.rule.Package pkg = builder.getPackage();
ruleBase.addPackage(pkg);
return ruleBase;
}
My Packages are not adding to RuleBase.It is returning null.
How to add the packages to ruleBase.Please suggest me
Thanks
--
View this message in context:
http://drools.46999.n3.nabble.com/How-to-add-Packages-to-RuleBase-tp36534...
Sent from the Drools: User forum mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users