Hello everybody,
I would appreciate some help with the compilation of a rule that involves
dynamically generated POJOs (minimal example at the end of the mail).
When I add the packages of the generated POJOs manually to the imported
packages of my Eclipse plug-in that executes the knowledge session
everything works fine.
When I use my custom classloader (that successfully loads all involved
classes, I checked this thoroughly) I get the following errors:
Unable to generate rule invoker. lts cannot be resolved to a type
Rule Compilation error lts cannot be resolved to a type
Do I need to change my rules just because the involved classes are now
loaded using my custom classloader?
Thanks for your help!
M. Kramer
This is the rule that only works if the package "lts" is listed under
"Import-Package" in the MANIFEST.MF:
import java.lang.String;
import java.util.ArrayList;
import java.util.HashMap;
import org.eclipse.emf.ecore.EObject;
global java.lang.String output;
global java.util.List list;
global java.util.List pclist;
rule "Aspect"
when
$s0Decl: lts.State(name == "a")
$s0: lts.State(this == $s0Decl)
then
java.util.List param = new ArrayList<HashMap<String,EObject>>();
java.util.List ids = new ArrayList<String>();
param.add($s0);
ids.add("0");
list.add(param);
pclist.add(ids);
end
This is the code that I am using to execute the rule:
void executeKnowledgeSession(String droolsRules, URLClassLoader
urlClassLoader, Iterable<EObject> iterable) {
KnowledgeBuilderConfiguration kBuilderConfiguration =
KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(null,
urlClassLoader);
KnowledgeBuilder knowledgeBuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder(kBuilderConfiguration);
Resource droolsRulesResource =
ResourceFactory.newByteArrayResource(droolsRules.getBytes());
knowledgeBuilder.add(droolsRulesResource, ResourceType.DRL);
if (knowledgeBuilder.hasErrors()) {
...
}
KnowledgeBaseConfiguration kBaseConfiguration =
KnowledgeBaseFactory.newKnowledgeBaseConfiguration(null, urlClassLoader);
KnowledgeBase knowledgeBase =
KnowledgeBaseFactory.newKnowledgeBase(kBaseConfiguration);
knowledgeBase.getKnowledgePackages().clear();
knowledgeBase.addKnowledgePackages(knowledgeBuilder.getKnowledgePackages());
StatelessKnowledgeSession knowledgeSession =
knowledgeBase.newStatelessKnowledgeSession();
knowledgeSession.setGlobal(...);
// execute the knowledge session
knowledgeSession.execute(iterable);
}
These are the exact errors that I get:
Unable to generate rule invoker. lts cannot be resolved to a type
lts cannot be resolved to a type
Rule Compilation error lts cannot be resolved to a type
Unable to generate rule invoker. : [Rule name='Aspect']
defaultpkg/Rule_Aspect_0DefaultConsequenceInvoker.java (22:883) : lts
cannot be resolved to a type
defaultpkg/Rule_Aspect_0DefaultConsequenceInvoker.java (22:901) : lts
cannot be resolved to a type
Rule Compilation error : [Rule name='Aspect']
defaultpkg/Rule_Aspect_0.java (6:322) : lts cannot be resolved to a type
--
View this message in context:
http://drools.46999.n3.nabble.com/Rule-Compilation-error-when-using-custo...
Sent from the Drools: User forum mailing list archive at
Nabble.com.