Importing JAVA bean into Drools Workbench

2,259 views
Skip to first unread message

Yotam b

unread,
Jan 8, 2015, 3:05:47 AM1/8/15
to drools...@googlegroups.com

I start using KIE Drools Workbench and I practice in creating DRL files so I can tutor pepole that are not programmers in creating rules.

I know how to create a JAVA class within the Workbench but I need to know how to import a class I already wrote that will be part of the statement.

For example: Employer - class I create within the Workbench Employee - class I developed in eclipse and wish to import into the Workbench

So the drl could look like this:

when
$employer:Employer(isHappy == true)
then
Employee emp = new Employee();
end
emp.setSalary(100);
insert(emp);

Any idea how can I import JAVA bean to use in KIE Drools Workbench?

Thanks!




Mohan Kumar

unread,
Jan 8, 2015, 4:34:36 AM1/8/15
to drools...@googlegroups.com
Hi,
    U r trying to access the drools workbench from ecllipse and version of the drools?

Yotam b

unread,
Jan 8, 2015, 4:38:14 AM1/8/15
to drools...@googlegroups.com
No I'm using the web version

בתאריך יום חמישי, 8 בינואר 2015 11:34:36 UTC+2, מאת Mohan Kumar:

Yotam b

unread,
Jan 8, 2015, 4:38:44 AM1/8/15
to drools...@googlegroups.com
No I'm using the web version

בתאריך יום חמישי, 8 בינואר 2015 11:34:36 UTC+2, מאת Mohan Kumar:
Hi,

Michael Anstis

unread,
Jan 8, 2015, 5:05:14 AM1/8/15
to drools...@googlegroups.com
1) Go to the Artifact (Maven) Perspective
2) Upload a JAR containing your classes
3) Go to the Authoring Perspective
4) Open your Project
5) Open Project Editor
6) Go to Dependencies section
7) Add "JAR from repository"
8) Save
9) Go to rule you want to author
10) Go to "Config" tab and import classes you want to use (unless the rule and classes are in the same package)
11) Author rule

--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/918b53ec-856c-44bc-ba3f-1733924a252d%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

ramesh...@gmail.com

unread,
Jan 8, 2015, 7:17:37 AM1/8/15
to drools...@googlegroups.com
Hi,

1) Create a jar file of the pojo's with pom in meta-inf directory and install it in your local maven repository.

2) in the work bench, go to project editor and add dependency of the jar.

3) add Import suggestions in the project editor.

4) go to config tab of the assets and add import of the class you need to use in the rule.

if you follow these steps, imported pojo will be visible in your rule editor.


Best Regards
Ramesh


On Thursday, January 8, 2015 1:35:47 PM UTC+5:30, Yotam b wrote:

Yotam b

unread,
Jan 8, 2015, 7:34:43 AM1/8/15
to drools...@googlegroups.com
,hi
Thank you for your answer
I did steps 1-5 but I can't find the Dependencies(I have "Explore","New Item","Tools" and "Repository")

בתאריך יום חמישי, 8 בינואר 2015 12:05:14 UTC+2, מאת Michael Anstis:

Michael Anstis

unread,
Jan 8, 2015, 2:40:13 PM1/8/15
to drools...@googlegroups.com
Project Editor contains a drop-down at the top of the screen including "Project General Settings", "Dependencies" and others... see attached.


dependencies.png

superseed77

unread,
Sep 14, 2015, 9:59:08 AM9/14/15
to Drools Usage
Very usefull

but at

4) go to config tab of the assets and add import of the class you need to use in the rule.
or
10) Go to "Config" tab and import classes you want to use (unless the rule and classes are in the same package)

I can't find config tab in kie drools workbench

any clue ?
Thanks

Michael Anstis

unread,
Sep 14, 2015, 5:13:43 PM9/14/15
to drools...@googlegroups.com

Config tab is on each editor; so once you've added your dependencies to the project create (for example) a new guided rule and the associated editor will have a Config tab.

For now ensure the package containing the class(es) you need are in the same package as the rule... there's additional complexity for rules/classes in differ packages but let's get the simplest case working for you first.

superseed77

unread,
Sep 15, 2015, 2:56:36 AM9/15/15
to Drools Usage
Thanks a lot

Yes my bean are in different package and I use the simple drl rule editor. This one seam not to have a config Tab.

You are right I should try simple case before: Bean in same package than rule and guided rule editor

Michael Anstis

unread,
Sep 15, 2015, 3:04:59 AM9/15/15
to drools...@googlegroups.com

OK... if you're doing a DRL/Technical Rule then you cannot get much simpler! The reason you're not seeing types that are in a different package is caused by additional filtering of types by the workbench.

Switch to the Administration Perspective and navigate to the "package name white list" which, by default, filters by the default package name created for new projects. Change the content of this file (either remove the default value or add your required package names) and save.

superseed77

unread,
Sep 15, 2015, 3:17:35 AM9/15/15
to Drools Usage
Ok thanks a lot for your advices; its works for guided rules
I'll give a try for drl

Murali S

unread,
Mar 28, 2017, 1:50:37 PM3/28/17
to Drools Usage
Hi Michael,

I created a test drl file after creating the project set up ( Repository / New Project / New Data models) and imported my bean into the Drl file,. Drool validation is fine without errors . Now i want to test this DRL fire. Can you assist me on the below.

1. How to import a .JAVA file which i wrote already with KieSession (Java file attached) 
2. Do i need a jBPM Form builder and a BPD  to test this DRL.
3. Do i need a JSP Forms  / Servlet approach to test the DRL triggering (Kie session in a servlet file)

Not able to locate the Config tab from the above convesation thread -  Please assist. 

Thanks 
Murali Sridhar.
DroolsTest.java
Kie Editor_Items.JPG

Michael Anstis

unread,
Mar 29, 2017, 3:17:35 AM3/29/17
to Drools Usage
I don't entirely follow what you're explaining, but this is some comments:-

1. Only "Message" in the Java class is a POJO you could use in rules.
2. You don't show any DRL, so I'm not sure what you're doing
3. The best way to import an existing Java class into the workbench is either:-
    a) Bundle as  a JAR and add the JAR as a project dependency (this is the preferred way)
    b) git clone your repository, add the Java class, commit and push back to the workbench
    c) You cannot use "New file" in the Workbench as this currently places everything in src/main/resources (including Java classes)
4. Depending on what version of the workbench you're using "Config" may be called "Data Objects".
5. You don't need a form or servlet or JSP to test a DRL file; using Test Scenarios should be sufficient. 

To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+unsubscribe@googlegroups.com.

To post to this group, send email to drools...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages