cancel
Showing results for 
Search instead for 
Did you mean: 

Java service task

ddtnero
Champ in-the-making
Champ in-the-making
Hi activiti community, I've a problem with java service task.
I'm trying to include a java class in my activiti project but I can not.
For understand the problem I wanna make an example.
If I have a class in myPROJE/src/mail/java called Operation and this class have a method called Print(), how can I call this class in the service?
I try:

<serviceTask id="javaService"
             name="My Java Service Task"
             activiti:expression="#{Operation.Print()}" />

or:

<serviceTask id="javaService"
             name="My Java Service Task"
             activiti:expression="#{myPROJE/src/mail/java/Operation.Print()}" />

The class operation has only one method. Do I Must move the class in a directory? Can you write a tag for invoke the method for me please?
5 REPLIES 5

trademak
Star Contributor
Star Contributor
Hi,

I would be an alternative to implement the JavaDelegate interface and configure your class in the service task class attribute.
If you want to use a class with the print method you have two options.
1. Define it as a Spring bean and define the service task expression accordingly
2. Set the class as a process variable and use a service task expression to invoke the print method on the variable.

Best regards,

ddtnero
Champ in-the-making
Champ in-the-making
So, I have this Class:

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

public class Operations implements JavaDelegate {
  public void execute(DelegateExecution execution) throws Exception {
    String var = (String) execution.getVariable("input");
    var = "Changed";
    execution.setVariable("input", var);
  }
}


Now in Eclipse, right click on the class -> Export… -> Java -> Jar file. And I put this file in activiti-5.6/apps/apache-tomcat-6.0.32/webapps/activiti-explorer/WEB-INF/lib.
In the diagram I make this choise:

http://imageshack.us/photo/my-images/69/javf.png/
http://imageshack.us/photo/my-images/221/mailjizkb.png/

But the result is this:

http://imageshack.us/photo/my-images/708/mailiq.png/

trademak
Star Contributor
Star Contributor
Hi,

You should use the Operations class with the class attribute of the Java service task, not the expression.

Best regards,

ddtnero
Champ in-the-making
Champ in-the-making
I've set java task as you can see

http://imageshack.us/photo/my-images/402/jav1a.png/

But I have an error:

http://imageshack.us/photo/my-images/715/regzg.png/


I've set the class browsing in the workspace of Eclipse and I have make the deploy with .jar file.
I have set var as field name for containing the result of Operation.execute(${employee}).
I can't set a Result variable because Java class doesn't want Result Variable.

Sorry if this problem is easy for you, but I can't solve…
Thanks.

trademak
Star Contributor
Star Contributor
Hi,

In a lot of the chapters of the Activiti in Action book I show how you can use the Java service task in various ways.
I think that would be a good read.

Best regards,