dextervip
dextervip

Reputation: 5069

How to correct "doesn't implement org.activiti.engine.delegate.JavaDelegate" error in Activiti

I am starting with Activiti and I am trying to create a service task. I created a netbeans java library project and coded the following class:

package com.processos.reuniao;

import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;

public class ListUsers implements JavaDelegate {

    @Override
    public void execute(DelegateExecution execution) throws Exception {
        String group = (String) execution.getVariable("group");
        System.out.println(group);
    }

}

Then I builded the library and copied the jar into tomcat lib folder at /lib, where I have activiti libraries also.

In my BPMN I have this service task:

<serviceTask id="servicetask1" name="List Users" activiti:class="com.processos.reuniao.ListUsers"></serviceTask>

When Activiti try to run this service task, It returns me this exeception:

Fev 27, 2013 5:31:32 PM com.vaadin.Application terminalError
SEVERE: Terminal error:
com.vaadin.event.ListenerMethod$MethodException
Cause: com.vaadin.event.ListenerMethod$MethodException
Cause: org.activiti.engine.ActivitiException: com.processos.reuniao.ListUsers doesn't implement org.activiti.engine.delegate.JavaDelegate nor org.activiti.engine.impl.pvm.delegate.ActivityBehavior

As shown in the class, It implements JavaDelegate. What I am doing wrong?

Upvotes: 1

Views: 3581

Answers (2)

Ironluca
Ironluca

Reputation: 3762

The reason for this error is classes loaded by different class loaders are not considered same.

I'm not sure of your environment; however, I faced the same issue running Activiti WAR in Tomcat.

Usually in class loader implementation, the parent class loader is asked to load the class first and then the current class loader attempts to load it.

Tomcat webapp class loader behaves differently. It loads the classes if it finds and if it cannot load, then it asks its parent Refer: Tomcat Class loading

This causes a problem, if the delegate implementation is kept outside of Activiti WEB-INF/lib. In this case, the delegate implementation and the JavaDelegateAdapter class are loaded by the 'common' class loader.

When Activiti creates the object of the delegate and does an 'instanceof', it is doing it with the JavaDelegateAdapter class loaded by webapp class loader.

Therefore, the 'instanceof' returns false and the above error is encountered.

Upvotes: 0

ATMTA
ATMTA

Reputation: 767

Try to add jar to the webapps/your-appplication/WEB-INF/lib directory or to webapps/activiti-explorer/WEB-INF/lib if you test workflow using activiti-explorer The best way to test process definitions is to use activiti-explorer. You can find activiti-explorer.war file in activiti distribution.
Activiti user guide - deployment with Activiti explorer

Upvotes: 4

Related Questions