Are you inserting the instance of the dynamically loaded class into the KnowledgeBase?<br>i.e. session.insert(dynamicInstance);<br><br>If not the rule won't get fired.<br><br><br>Cheers,<br><br>Swapnil<br><br><div class="gmail_quote">
2009/11/3 Hemanth kumar <span dir="ltr"><<a href="mailto:hemanth@saha.in">hemanth@saha.in</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
hi,<br>
Im working on a sample test project.<br>
In that im dynamically creating a class ( fact) and compiling it.<br>
<br>
here is my test project<br>
--------------------------------------------------------------------------------------<br>
mainJavaclass<br>
<br>
<br>
public void runRule()<br>
{<br>
try {<br>
System.out.println("\nRunning rule\n");<br>
<br>
// go !<br>
<br>
URL[] urls = new URL[]{ new<br>
URL("file://"+path) };<br>
<br>
URLClassLoader ucl = new<br>
URLClassLoader(urls);<br>
Class<?> clazz =<br>
ucl.loadClass("test.Message");<br>
Object classObj = clazz.newInstance();<br>
<br>
<br>
Method method =<br>
clazz.getDeclaredMethod("setMessage", new Class[]{String.class});<br>
<br>
//System.out.println("facts loaded\n");<br>
<br>
method.invoke(classObj, new<br>
Object[]{"Hello"});<br>
<br>
<br>
<a href="http://log.info" target="_blank">log.info</a>("==== Calling Rule Runner ======");<br>
<br>
Collection facts = new ArrayList();<br>
facts.add(classObj);<br>
<br>
<br>
// Load and fire our rules files against the<br>
data<br>
new<br>
RuleRunner().runStatelessRules(RULES_FILES, null, facts, null, null,<br>
logger);<br>
<br>
}<br>
catch (Throwable t) {<br>
t.printStackTrace();<br>
}<br>
<br>
}<br>
<br>
----------------------------------------------------------------------<br>
Fact<br>
<br>
package test;<br>
public class Message{<br>
private String message;<br>
public String getMessage(){<br>
return this.message;<br>
}<br>
<br>
public void setMessage(String message) {<br>
this.message = message;<br>
}<br>
<br>
}<br>
<br>
<br>
------------------------------------------------------------------------<br>
sample rule<br>
<br>
package test<br>
import test.Message;<br>
<br>
rule "Your First Rule"<br>
dialect "mvel"<br>
when<br>
m:Message(message != "Good Bye" )<br>
then<br>
System.out.println("First Rule fired "+m.message );<br>
modify(m){ message = "Good Bye"};<br>
end<br>
-----------------------------------------------------------------<br>
<a href="http://old.nabble.com/file/p26160051/console.PNG" target="_blank">http://old.nabble.com/file/p26160051/console.PNG</a> console.PNG<br>
<br>
what happens is when i was running the project inside eclipse IDE it works<br>
fine but when i hosted in tomcat and calling from outside ide the rule is<br>
not getting fired.<br>
I think the dyanamically loaded class is not recognised by the rule engine.<br>
<br>
suggest me any ideas or post an working example<br>
<br>
Hemanth<br>
<font color="#888888">--<br>
View this message in context: <a href="http://old.nabble.com/Class-loader-problem-tp26160051p26160051.html" target="_blank">http://old.nabble.com/Class-loader-problem-tp26160051p26160051.html</a><br>
Sent from the drools - user mailing list archive at Nabble.com.<br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">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>
</font></blockquote></div><br>