Hi sir ,
I am facing one issue regarding dyamic class cretion and inserting it's
object into drools memory.
i have created a dyanmic class test and loads it like that
MyClassLoader clr =new
MyClassLoader(Obj.getClass().getClassLoader());
Obj.clazz= clr.loadClass("test");
//Drools Configuration
KnowledgeBuilderConfiguration kbc =
KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(null,clazz.getClassLoader());
KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder(kbc);
String path = System.getProperty("user.dir");
StringBuilder drlFile = new StringBuilder(path);
drlFile.append(System.getProperty("file.separator")).append("myRule.drl");
kbuilder.add(ResourceFactory.newFileResource(drlFile.toString()),
ResourceType.DRL);
if (kbuilder.hasErrors())
{
System.out.println(kbuilder.getErrors());
return;
}
KnowledgeBaseConfiguration kbaseConfig
=KnowledgeBaseFactory.newKnowledgeBaseConfiguration(null,
clazz.getClassLoader());
kbase = KnowledgeBaseFactory.newKnowledgeBase(kbaseConfig);
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
ksession = kbase.newStatefulKnowledgeSession();
Now my drl file is like that
package dyanmicclass;
dialect "java"
rule mytest1
when
$tx : test($pp : name )
then
globalArrayList.add($tx);
System.out.println($tx );
end
this is giving me a error
KnowledgeBuilder created.
Unable to generate rule invoker. : [Rule name='mytest1']
dyanmicclass/Rule_mytest1_0DefaultConsequenceInvoker.java (22:886) :
test cannot be resolved to a type
dyanmicclass/Rule_mytest1_0DefaultConsequenceInvoker.java (22:898) :
test cannot be resolved to a type
Rule Compilation error : [Rule name='mytest1']
dyanmicclass/Rule_mytest1_0.java (6:214) : txn cannot be resolved to
a type
but while i am doing like that
dialect "java"
rule mytest1
when
$tx : test($pp : name )
then
System.out.println($pp );
end
it gives no error .
I am not able to find the cause of the problem .
am i wrong in any configuaration.
Thanks
Saurabh