[rules-users] External Jar/Pojo in Drools Workbench.

Michael Anstis michael.anstis at gmail.com
Thu Apr 10 08:40:21 EDT 2014


OK, I imported your JAR and created a rule as shown below.

The Guided Rule Editor had the option to select the enums for Country.

Theonly issue I had was with "Destination" itself - as it should be a lower
case "d". Drools Compiler did report an error that  is was ..."Unable to
create Field Extractor for 'Destination'Field/method 'destination' not
found for class 'com.sample.GenericDataObject'". I suspect if you change
the field name to "destination" it would work OK.

This was with the latest code @master in github.

1.|package org.anstis.p1;2.|3.|import java.lang.Number;4.|import
 com.sample.GenericDataObject;5.|import
 com.sample.GenericDataObject.Airline;6.|import
 com.sample.GenericDataObject.Country;7.|import com.sample.Result;8.|9.|rule
 "r1"10.|    dialect "mvel"11.|    when12.|        GenericDataObject(
Destination == Country.Egypt )13.|    then14.|end


On 10 April 2014 12:58, Leonard93 <leonardlindenau at hotmail.com> wrote:

> Hello everyone, I have a small question/problem.
>
> I have created a class (POJO) in Eclipse and I want to be able to write
> rules over this class in the Drools Workbench, thus I exported the class
> and
> the classes it depends on (1 other class) to a Jar and imported it in the
> Drools workbench.
>
> Now what I did next is I added the jar dependency to my workbench project,
> created a new datamodel and set its super class to the external class from
> the jar and left the rest empty.
>
> When I then try to use this datamodel in a guided rule or anything I can
> access the variables defined in the external class fine when using the rule
> editor. But when I save I get various compiler errors.
>
> Currently I tried to make a rule template and I got these errors (I am
> using
> the standard example project to test it out):
>
> Unable to create Field Extractor for *'Destination'Field/method
> 'destination'* not found for class '*org.mortgages.Test' *
>
> Unable to Analyse Expression *Destination ==
> GenericDataObject$Country.Germany*: [Error: unable to resolve method using
> strict-mode: *org.mortgages.Test.GenericDataObject$Country()]* [Near :
> {...*
> Destination == GenericDataObject$Country.Germ ....}]* ^ [Line: 9, Column:
> 2]
>
>
> The class from the jar looks like this:
> public class GenericDataObject {
>
>     public enum Country
>     {
>         Egypt,
>         Germany,
>         Turkey,
>         France,
>         Unknown
>     }
>
>     public GenericDataObject()
>     {
>         result = new Result();
>     }
>
>     public Result result;
>     public Country Destination;
>
>     public void setDiscount(int amount)
>     {
>         result.discount = amount;
>     }
> }
>
> public class Result
> {
>     public int discount;
>
>     public Result()
>     {
>         discount = 0;
>     }
> }
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/External-Jar-Pojo-in-Drools-Workbench-tp4029190.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20140410/545fd493/attachment.html 


More information about the rules-users mailing list