Re: [rules-users] Rule Compilation error when using custom classloader
Hello, could it be that the same rules compile with the standard classloader but not with a custom one because of declared types? I found some pointers to this in older posts but got no clue what it is or how I can use it to get my apparently correct rules to compile. Any ideas? Thanks, M. Kramer P.S. In case you consider my example incomplete because the code for the business class State is missing: it is the plain code that is generated by EMF for a metaclass with a single String attribute name: public interface State extends EObject { String getName(); void setName(String value); } public class StateImpl extends EObjectImpl implements State { protected static final String NAME_EDEFAULT = null; protected String name = NAME_EDEFAULT; protected StateImpl() { super(); } @Override protected EClass eStaticClass() { return LtsPackage.Literals.STATE; } public String getName() { return name; } public void setName(String newName) { String oldName = name; name = newName; if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, LtsPackage.STATE__NAME, oldName, name)); } public Object eGet(int featureID, boolean resolve, boolean coreType) { switch (featureID) { case LtsPackage.STATE__NAME: return getName(); } return super.eGet(featureID, resolve, coreType); } @SuppressWarnings(unchecked) @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case LtsPackage.STATE__NAME: setName((String)newValue); return; } super.eSet(featureID, newValue); } @Override public void eUnset(int featureID) { switch (featureID) { case LtsPackage.STATE__NAME: setName(NAME_EDEFAULT); return; } super.eUnset(featureID); } @Override public boolean eIsSet(int featureID) { switch (featureID) { case LtsPackage.STATE__NAME: return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name); } return super.eIsSet(featureID); } @Override public String toString() { if (eIsProxy()) return super.toString(); StringBuffer result = new StringBuffer(super.toString()); result.append( (name: ); result.append(name); result.append(')'); return result.toString(); } } -- View this message in context: http://drools.46999.n3.nabble.com/Rule-Compilation-error-when-using-custom-classloader-tp3824716p3877839.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Rule Compilation error when using custom classloader
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 ArrayListHashMaplt;String,EObject(); java.util.List ids = new ArrayListString(); 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, IterableEObject 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-custom-classloader-tp3824716p3824716.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users