[rules-users] couuld not load fact to rule engine

Hemanth kumar hemanth at saha.in
Wed Oct 28 04:00:59 EDT 2009


hi isterin,

I have less knowledge of what you are saying.

would you please send an working example 

thanx

hemanth


isterin wrote:
> 
> You have to inject the same class loader which loaded your dynamic
> class into the drools.  Here is the blog post outlining how to do it
> as well as some caveats with classloaders...
> 
> http://www.ilyasterin.com/blog/2009/10/java-multiple-class-loaders-issue.html
> 
> On Tue, Oct 27, 2009 at 2:30 AM, Hemanth kumar <hemanth at saha.in> wrote:
>>
>>
>> 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
>> -----------------------------------------------------------------
>> console file  http://www.nabble.com/file/p26072723/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
>>
>> Hemanth
>> --
>> View this message in context:
>> http://www.nabble.com/couuld-not-load-fact-to-rule-engine-tp26072723p26072723.html
>> Sent from the drools - user mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
> 
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
> 
> 

-- 
View this message in context: http://www.nabble.com/couuld-not-load-fact-to-rule-engine-tp26072723p26090658.html
Sent from the drools - user mailing list archive at Nabble.com.





More information about the rules-users mailing list