Java service task with Flowable workflow

Flowable provides the Java service task that allows to invoke an external Java class. And here, we will see how to do it. You shoud practice the previous tutorial to be clear with the process model design before working on this.

Create an external Java class as a jar file

  1. In Eclipse, create a new Maven Project.
    1. Check Create a simple project→Next
    2. Add Group Id and Artifact Id: org.flowable → Finish
  2. In your project, edit the file pom.xml by adding:

        <dependencies>
          <dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-engine</artifactId>
            <version>6.7.2</version>
          </dependency>
        </dependencies> 
  3. Create a package org.flowable.
  4. In the package org.flowable, create a class MyJavaDelegate with the following code:

    package org.flowable;
     
    import org.flowable.engine.delegate.DelegateExecution;
    import org.flowable.engine.delegate.JavaDelegate;
     
    public class MyJavaDelegate implements JavaDelegate {
     
    	public void execute(DelegateExecution execution) {
    		String var = (String) execution.getVariable("input");
    		var = var.toUpperCase();
    		execution.setVariable("input", var);
    	}
    }
  5. Right click on your project and select Run As→Maven Install to build a jar file.
  6. Copy a jar file in the folder target to TOMCAT_HOME\webapps\flowable-ui\WEB-INF\lib
  7. Restart your tomcat.

Design the "Displaying Upper Case" process model

  1. In Activiti, login as admin “admin/test” with Modeler App→Processes→Create Process.
  2. Enter new model Model name: Displaying Upper Case, and Model key:uppercase. Click Create new model.
  3. Design a process model by drag and drop model elements, you should have something similar to this picture:

  4. On the start event, specify the following properties:
    1. Initiator: initiator
    2. Form reference→New form, with Form name: Initiate Upper Case, and Form key: initiate_upper_case, then click on Create form.
      1. Design the form by drag and drop the component, by add new Text, then on click on edit icon after hover on, and update the Label: Input, then click Close.
      2. Click on the Save icon, then Save and close editor.
  5. On the Get uppercase activity, specify the property Class: org.flowable.MyJavaDelegate
  6. On the output activity, specify the following properties:
    1. Assignments→Assignment: Assigned to process initiator
    2. Form reference→New form, with Form name: Output Upper Case, and Form key: output_upper_case, then click on Create form.
      1. Add Text, then change the label: Output, check Override id?, then id: input.
  7. Click on Save the model icon, then click on Save and close editor.
  8. In Apps→Create App:
    1. App definition name:Service connection
    2. App definition key:service_connection
    3. Then Create new app definition
  9. Clik on Edit included models, select your Displaying Upper Case process model, then go to Save and check published, and finally Save and close editor.

Executing a process model

  1. Go to Service connection→Processes→Start a process, select your newly created process model.
  2. Select Displaying upper Case.
  3. Enter some text in the Input, then click on Start process.


  4. Go to Processes→Inbox and select you instance, then click on Show diagram to see the status of your executing process.


    As you can see, the service task Get uppercase has automatically executed and invoked an external java class MyJavaDelegate. Now the current task is output which needed to be handled by you.
  5. Select Tasks→Inbox to see the output, then click on Complete button to end this process.


teaching_assistant/workflow/flowable_java_service_task.txt · Last modified: 2025/11/20 18:42 by Ali
Back to top
CC Attribution-Share Alike 4.0 International
chimeric.de = chi`s home Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0