Oops, it was already mentioned, Sorry ..<br><br><div class="gmail_quote">On Fri, Dec 5, 2008 at 11:01 PM, Michal Bali <span dir="ltr">&lt;<a href="mailto:michalbali@gmail.com">michalbali@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I vaguely remember reading about similar issues with OSGi. It was solved by using so called &quot;buddy loading&quot;:<br>
<a href="http://help.eclipse.org/ganymede/topic/org.eclipse.platform.doc.isv/reference/misc/buddy_loading.html" target="_blank">http://help.eclipse.org/ganymede/topic/org.eclipse.platform.doc.isv/reference/misc/buddy_loading.html</a><br>

Hope it helps.<div><div></div><div class="Wj3C7c"><br><br><div class="gmail_quote">On Fri, Dec 5, 2008 at 10:11 PM, Faron Dutton <span dir="ltr">&lt;<a href="mailto:fgdutton@gmail.com" target="_blank">fgdutton@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Once I work out the kinks, I could provide the code (e.g.,<br>
ClassLoaders) on the wiki.<br>
<br>
Unfortunately, Drools cannot anticipate dependencies and there is no<br>
special sauce for adding them at runtime. It would be nice if Drools<br>
was more consistent in its use of ClassLoader. I know this is vague;<br>
I&#39;ll try to provide some example later. Its been about two weeks since<br>
I wrote the solution so I&#39;ll need to go back and find them again. MVEL<br>
appears to be a bigger issue though. The ClassLoader should really be<br>
associated with the working memory instead of the thread.<br>
<div><div></div><div><br>
On Fri, Dec 5, 2008 at 4:52 PM, Edson Tirelli &lt;<a href="mailto:tirelli@post.com" target="_blank">tirelli@post.com</a>&gt; wrote:<br>
&gt;<br>
&gt; &nbsp; &nbsp;Thanks a lot for the information. Maybe we should add this to a Wiki<br>
&gt; page?<br>
&gt;<br>
&gt; &nbsp; &nbsp;From a Drools perspective, a solution like you proposed should work for<br>
&gt; any case, since we also internally tell MVEL to use the same classloader<br>
&gt; hierarchy... unless there is some unknown bug.<br>
&gt;<br>
&gt; &nbsp; &nbsp;Regarding declaring dependencies, I don&#39;t understand how Drools could<br>
&gt; declare such dependency since the fact classes are defined and provided by<br>
&gt; users and not known by drools in advance. Is there some default mechanism<br>
&gt; that we could implement to support such things &quot;automagically&quot; in OSGi<br>
&gt; deployments?<br>
&gt;<br>
&gt; &nbsp; &nbsp;[]s<br>
&gt; &nbsp; &nbsp;Edson<br>
&gt;<br>
&gt; 2008/12/5 Faron Dutton &lt;<a href="mailto:fgdutton@gmail.com" target="_blank">fgdutton@gmail.com</a>&gt;<br>
&gt;&gt;<br>
&gt;&gt; I have successfully loaded rules and facts from other bundles in Eclipse<br>
&gt;&gt; 3.4.<br>
&gt;&gt;<br>
&gt;&gt; I encountered the same issue, which is due to the ClassLoader behavior<br>
&gt;&gt; defined by OSGi v4. Eclipse 3.3 introduced the new behavior and<br>
&gt;&gt; Eclipse 3.4 aggressively adheres to the specification. Drools attempts<br>
&gt;&gt; to access a Class through a reference to a ClassLoader, which by<br>
&gt;&gt; default is its bundle ClassLoader. MVEL attempts to access a Class<br>
&gt;&gt; through the context ClassLoader, which OSGi sets to the bundle&#39;s<br>
&gt;&gt; ClassLoader. The problem arises because neither the Drools bundle nor<br>
&gt;&gt; the MVEL bundle (I have each Drools artifact in a separate bundle)<br>
&gt;&gt; declare a dependency on the package containing the fact&#39;s Class.<br>
&gt;&gt; Therefore, OSGi does not add that package to the bundle&#39;s ClassLoader<br>
&gt;&gt; and you get a ClassNotFoundException when Drools attempts to find the<br>
&gt;&gt; Class.<br>
&gt;&gt;<br>
&gt;&gt; I worked around this issue by doing several things:<br>
&gt;&gt; 1) Created an implementation of ClassLoader that delegates to the<br>
&gt;&gt; bundle (BundleClassLoader).<br>
&gt;&gt; 2) Created a composite ClassLoader that contains many bundle<br>
&gt;&gt; ClassLoaders (CompositeClassLoader).<br>
&gt;&gt; 3) For each bundle containing a rule or fact, wrap it in a<br>
&gt;&gt; BundleClassLoader and add it to the CompositeClassLoader.<br>
&gt;&gt; 4) Pass the CompositeClassLoader to the methods mentioned in Edson&#39;s post.<br>
&gt;&gt; 5) Wrap the working memory in a Class that sets the context<br>
&gt;&gt; ClassLoader before each method invocation and restores the original<br>
&gt;&gt; context ClassLoader afterwards.<br>
&gt;&gt;<br>
&gt;&gt; This takes care of most but not all of the issues. Specifically, some<br>
&gt;&gt; invocations of MVEL still fail but the system works. I am continuing<br>
&gt;&gt; to investigate a more elegant solution.<br>
&gt;&gt;<br>
&gt;&gt; Faron.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; On Wed, Dec 3, 2008 at 10:11 AM, Edson Tirelli &lt;<a href="mailto:tirelli@post.com" target="_blank">tirelli@post.com</a>&gt; wrote:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; &nbsp; &nbsp;What do you mean by &quot;facts in other plugins&quot;?<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; &nbsp; &nbsp;If your facts are loaded by a different classloader hierarchy, you<br>
&gt;&gt; &gt; need<br>
&gt;&gt; &gt; to set the facts classloader in:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; PackageBuilderConfiguration.setClassLoader(); &nbsp;// to compile the rules<br>
&gt;&gt; &gt; RulebaseConfiguration.setClassLoader(); // to create the rulebase and<br>
&gt;&gt; &gt; run it<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; &nbsp; &nbsp;[]s<br>
&gt;&gt; &gt; &nbsp; &nbsp;Edson<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; 2008/12/2 keithnielsen &lt;<a href="mailto:keithnielsen@discover.com" target="_blank">keithnielsen@discover.com</a>&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Further testing shows that while the rules engine can locate facts from<br>
&gt;&gt; &gt;&gt; other<br>
&gt;&gt; &gt;&gt; plug-ins (facts located in the same plugin as the rules engine work<br>
&gt;&gt; &gt;&gt; fine,<br>
&gt;&gt; &gt;&gt; but not realistic to expect that all facts will be co-located in the<br>
&gt;&gt; &gt;&gt; same<br>
&gt;&gt; &gt;&gt; plugin), an attempt to reconstitute them using the ByteArrayClassloader<br>
&gt;&gt; &gt;&gt; will<br>
&gt;&gt; &gt;&gt; not work. Has anyone been successful using facts located in other<br>
&gt;&gt; &gt;&gt; plug-ins?<br>
&gt;&gt; &gt;&gt; I am using Drools 5.M2 with Eclipse 3.4.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; keithnielsen wrote:<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; I have the following rule:<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; rule &quot;Retrieve CID Presentation Model&quot;<br>
&gt;&gt; &gt;&gt; &gt; &nbsp; &nbsp; &nbsp; ruleflow-group &quot;RetrieveCID&quot;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; &nbsp; &nbsp; &nbsp; when<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; CIDPresentationModel($cidValue:cidValue,$cidExpirationDate:expirationDate)<br>
&gt;&gt; &gt;&gt; &gt; &nbsp; &nbsp; &nbsp; then<br>
&gt;&gt; &gt;&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; boolean cidResult =<br>
&gt;&gt; &gt;&gt; &gt; cidService.verifyCIDIsValid($cidValue,$cidExpirationDate);<br>
&gt;&gt; &gt;&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CIDResult result = new CIDResult(cidResult);<br>
&gt;&gt; &gt;&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; insert(result);<br>
&gt;&gt; &gt;&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println(&quot;Executing: Retrieve CID<br>
&gt;&gt; &gt;&gt; &gt; Presentation<br>
&gt;&gt; &gt;&gt; &gt; Model&quot;);<br>
&gt;&gt; &gt;&gt; &gt; end<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; Deep in the bowels of drools there is a call to<br>
&gt;&gt; &gt;&gt; &gt; ClassFieldAccessorFactory.getClassFieldReader where it attempts to<br>
&gt;&gt; &gt;&gt; &gt; create<br>
&gt;&gt; &gt;&gt; &gt; a class using the byte array classloader, i.e. final Class&lt;?&gt;<br>
&gt;&gt; &gt;&gt; &gt; newClass =<br>
&gt;&gt; &gt;&gt; &gt; byteArrayClassLoader.defineClass(className, bytes,PROTECTION_DOMAIN).<br>
&gt;&gt; &gt;&gt; &gt; Its<br>
&gt;&gt; &gt;&gt; &gt; at this point that a NoClassDefFoundError on the<br>
&gt;&gt; &gt;&gt; &gt; BaseObjectClassFieldReader. From what I understand of<br>
&gt;&gt; &gt;&gt; &gt; NoClassDefFoundError<br>
&gt;&gt; &gt;&gt; &gt; it can result when there are two sources of the same class in the<br>
&gt;&gt; &gt;&gt; &gt; classpath or if there is some reference from the class resulting in<br>
&gt;&gt; &gt;&gt; &gt; the<br>
&gt;&gt; &gt;&gt; &gt; error to another class that can not be resolved. It only appears in<br>
&gt;&gt; &gt;&gt; &gt; situations where there is fields involved. It doesnt seem to matter<br>
&gt;&gt; &gt;&gt; &gt; how<br>
&gt;&gt; &gt;&gt; &gt; simple the object is, the minute I try to use field assignment it<br>
&gt;&gt; &gt;&gt; &gt; throws<br>
&gt;&gt; &gt;&gt; &gt; an error.<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; The rules engine is running as an Eclipse plug-in.<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; --<br>
&gt;&gt; &gt;&gt; View this message in context:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; <a href="http://www.nabble.com/NoClassDefFoundError%3A-BaseObjectClassFieldReader-tp20802217p20806634.html" target="_blank">http://www.nabble.com/NoClassDefFoundError%3A-BaseObjectClassFieldReader-tp20802217p20806634.html</a><br>


&gt;&gt; &gt;&gt; Sent from the drools - user mailing list archive at Nabble.com.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; _______________________________________________<br>
&gt;&gt; &gt;&gt; rules-users mailing list<br>
&gt;&gt; &gt;&gt; <a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
&gt;&gt; &gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; --<br>
&gt;&gt; &gt; &nbsp;Edson Tirelli<br>
&gt;&gt; &gt; &nbsp;JBoss Drools Core Development<br>
&gt;&gt; &gt; &nbsp;JBoss, a division of Red Hat @ <a href="http://www.jboss.com" target="_blank">www.jboss.com</a><br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; _______________________________________________<br>
&gt;&gt; &gt; rules-users mailing list<br>
&gt;&gt; &gt; <a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
&gt;&gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; rules-users mailing list<br>
&gt;&gt; <a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; &nbsp;Edson Tirelli<br>
&gt; &nbsp;JBoss Drools Core Development<br>
&gt; &nbsp;JBoss, a division of Red Hat @ <a href="http://www.jboss.com" target="_blank">www.jboss.com</a><br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; rules-users mailing list<br>
&gt; <a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;<br>
&gt;<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div><br>
</div></div></blockquote></div><br>