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