Here's how to add a handler inside an eclipse maven project. I call it the Awesome handler, but you have to choose a more specific name.
1) First create a work item definition file in the src / main / resources / WorkItemDefinitions.wid file. My icon file is located in src / main / resources.
import org.drools.core.process.core.datatype.impl.type.StringDataType; [ [ "name" : "Awesome", "parameters" : [ "Message1" : new StringDataType(), "Message2" : new StringDataType() ], "displayName" : "Awesome", "icon" : "icon-info.gif" ] ]
2) Create a work item handler configuration file in the src / main / resources / META-INF / CustomWorkItemHandlers.conf file
[ "Awesome": new org.jbpm.examples.util.handler.AwesomeHandler() ]
3) Create a drools session configuration file: src / main / resources / META-INF / drools.session.conf
drools.workItemHandlers = CustomWorkItemHandlers.conf
4) Create a handler so that it matches the class that you defined in step 2
public class AwesomeHandler implements WorkItemHandler { public AwesomeHandler() { super(); } public void executeWorkItem(WorkItem workItem, WorkItemManager manager) { System.out.println("Executing Awesome handler"); manager.completeWorkItem(workItem.getId(), null); } public void abortWorkItem(WorkItem workItem, WorkItemManager manager) { System.out.println("Aborting"); } }
5) After installing the handler, you must register it in your session.
//Get session KieSession ksession = runtime.getKieSession(); //Register handlers ksession.getWorkItemManager().registerWorkItemHandler("Awesome", new AwesomeHandler());
At this point, you should restart eclipse. When an eclipse opens, the palette should have a tab "Custom Tasks". It must contain an Awesome entry with the indicated icon.