[rules-users] Drools Dyanmic Class creation Problem
Michael Anstis
michael.anstis at gmail.com
Sat Mar 26 15:21:04 EDT 2011
1) The only difference appears to be the use of presumably a global. Do
define this in your DRL and set its value before invoking fireAllRules?
2) The error messages states "txn cannot be resolved to a type" however
"txn" does not appear in your pasted rule. Is something missing?
2011/3/26 Wolfgang Laun <wolfgang.laun at gmail.com>
> If there is a package header on a DRL file it defines a package the same
> way it does for a Java source file. Also, visibility of classes works the
> same way: if a class is in the same package as the DRL, you don't have to
> import it; otherwise you have to.
>
> -W
>
>
> 2011/3/26 saurabh maheshwari <maheshwari.saurabh03 at gmail.com>
>
>> 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
>>
>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20110326/6eee46c8/attachment.html
More information about the rules-users
mailing list