This content is dedicated to our next version. It is work in progress: its content will evolve until the new version is released.

Before that time, it cannot be considered as official.

Create administration tools

Discover how to create tools to administer your Bonita system using Maven and Java.

Getting started

The example proposes to list the failed tasks, and is wrapped in a script so that it can be executed in an environment with no window manager.

You need to be familiar with building a Maven project with Bonita as a dependency. You also need to be familiar with using the Bonita Engine APIs. If this is not the case, follow this tutorial. The Engine API overview contains a list of the APIs with a short description of each one. For details of the methods available in the Bonita Engine APIs, see the Javadoc.

This example uses the Bonita Engine Java APIs but there is also a REST API.

In this example, the Maven project has the following settings:

  • Group Id: org.mycompany.bonita

  • Artifact Id: bonita-cli

You must have a running Bonita system. The simplest way to do this is to run a Bonita Tomcat bundle locally. You also need a user: in this example the user has username admin and password secret.

Write a class that lists failed tasks

Bonita provides a client to leverage the Java APIs. This is the easiest starting point for an application, so this is what we will use in the example.

Set up your Maven project with a maven dependency to bonita-client. Then create a class to execute the business logic. In this example, the class is called ListFailedTasksCmd. It implements Callable<Void>, and calls methods to log in the API, then to execute the business logic, and finally to log out from the API.

public Void call() throws Exception {
    try {
    } finally {

The business logic of this example gets a list of the failed tasks and prints them to standard output. The maximum number of failed activities to retrieve is provided by the class field nbTodisplay. The method printFailedTasks is doing the actual job of searching for activities whose state is FAILED.

Like for any methods in the API listing elements, the searchActivities method takes paging information to limit the number of elements to retrieve. This prevents clients from retrieving too much data at the same time and filling up the whole memory. This is a common way to avoid users getting OutOfMemory errors. It is better to make several successive calls to the API than to retrieve too much data.
protected void printFailedTasks() throws BonitaHomeNotSetException,
    		ServerAPIException, UnknownAPITypeException, SearchException {

ProcessRuntimeAPI taskAPI = (ProcessRuntimeAPI) TenantAPIAccessor.getProcessAPI(session);
SearchOptions failedSearchOptions = new SearchOptionsBuilder(0,nbTodisplay)
    .filter(ActivityInstanceSearchDescriptor.STATE_NAME, ActivityStates.FAILED_STATE)

SearchResult<ActivityInstance> failedTasks = taskAPI.searchActivities(failedSearchOptions);

See the complete source code for this class is in

Create a main class

Let’s create a class that will be the entry point of our application. The CLI will simply delegate to our ListFailedTasksCmd the responsibility to fetch failed tasks and display them on the standard output. The CLI will take as input parameters the username, password and the maximum number of failed tasks to display.

public static void main(String[] args) {
  if(args.length != 3) {
    throw new IllegalArgumentException("Usage: you should provide <username> <password> <number of tasks to display>");

  try {
       new ListFailedTasksCmd(args[0], args[1], Integer.parseInt(args[2])).call();
  } catch (Exception e) {

Prepare packaging

As we have seen, the tool has several dependencies required to be executed. This means that our classes should be packaged along with these dependencies in a single bundle. To do this, build a zip with all the resources that the system will require to run the CLI.

Declare an Assembly

Create an assembly.xml file at the root to describe the final packaging.

<assembly xmlns="" xmlns:xsi=""

This assembly gathers all the dependencies into a lib folder along with all the content of the src/main/resources before zipping the whole collection. At the end we should get the following structure in a zip:

   |- bonita-cli.jar

Update the pom.xml file to call the assembly when building the project


The maven-assembly-plugin enables us to generate the zip as described in assembly.xml file with the specified zipName, e.g. Bonita-CLI-1.0.0.

Make the bonita-cli.jar executable

In order to launch the expected class,, edit the pom.xml and add the following lines. This will create a manifest during the build of the Maven project in the jar file which contains the main class.


Build and test

Right click on the project, select Run As > Maven Install. The output is located in /target. Open a console, go to the target folder, and unzip Before executing make sure to configure the bonita client to point the bonita engine by editing ${bonita.home}/engine-client/conf/ For example:

org.bonitasoft.engine.api-type = HTTP
server.url = http://localhost:8080 = bonita

To test our main class, execute the following command:

  • On Linux:java -jar lib/*.jar admin secret 10 -Dbonita.home=\pwd`/bonita`

  • On Windows:java -Dbonita.home=bonita -jar lib/bonita-cli-1.0.0.jar admin secret 10

These commands are cumbersome, so the next section explains how to create a script to hide the complexity.

Wrap in a Shell script

In the resources folder of your project, create a new file or bonita-cli.bat:

java -Dbonita.home=\`pwd\`/bonita -jar lib/bonita-cli-*.jar $*


java -Dbonita.home=bonita -jar lib/bonita-cli-1.0.0.jar %*

Build the whole project again. When the build completes, the zip file should contain the following structure:

Zip file structure

Run the appropriate script:

  • On Linux:./ admin secret 10

  • On Windows:bonita-cli.bat admin secret 10

Here is an example of output:

List of activities:(1 item(s) found)
  State   On      id      Name
  failed  16:11   100     Review Git Pull Request from: N Chabanoles

Complete code example

package org.mycompany.bonita.cli.cmd;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.concurrent.Callable;

import org.bonitasoft.engine.api.ProcessRuntimeAPI;
import org.bonitasoft.engine.api.TenantAPIAccessor;
import org.bonitasoft.engine.bpm.flownode.ActivityInstance;
import org.bonitasoft.engine.bpm.flownode.ActivityInstanceSearchDescriptor;
import org.bonitasoft.engine.bpm.flownode.ActivityStates;
import org.bonitasoft.engine.exception.BonitaHomeNotSetException;
import org.bonitasoft.engine.exception.SearchException;
import org.bonitasoft.engine.exception.ServerAPIException;
import org.bonitasoft.engine.exception.UnknownAPITypeException;
import org.bonitasoft.engine.platform.LoginException;
import org.bonitasoft.engine.session.APISession;

public class ListFailedTasksCmd implements Callable<Void> {
    private static final String ROW_SEPARATOR = "\n";
	private static final String COL_SEPARATOR = "\t";

	private String userName;
	private String password;
	private APISession session;
	private int nbTodisplay;

	public ListFailedTasksCmd(String user, String pass, int nbTodisplay) {
		userName = user;
		password = pass;
		this.nbTodisplay = nbTodisplay;

	public Void call() throws Exception {
		try {
		} finally {
		return null;

	protected void printFailedTasks() throws BonitaHomeNotSetException,
			ServerAPIException, UnknownAPITypeException, SearchException {
		ProcessRuntimeAPI taskAPI = (ProcessRuntimeAPI) TenantAPIAccessor
		SearchOptions failedSearchOptions = new SearchOptionsBuilder(0,
		SearchResult<ActivityInstance> failedTasks = taskAPI

	protected void print(SearchResult<ActivityInstance> failedTasks) {
		List<ActivityInstance> activities = failedTasks.getResult();
		StringBuffer line = new StringBuffer();
		// Header
		line.append(ROW_SEPARATOR).append("List of activities:")
				.append("(" + failedTasks.getCount() + " item(s) found)")
		// Display in a table layout
		for (ActivityInstance activityInstance : activities) {
					new SimpleDateFormat("HH:MM").format(activityInstance

	private void logout() {
		if (session != null) {
			try {
			} catch (Exception e) {

	protected void login() throws LoginException, BonitaHomeNotSetException,
			ServerAPIException, UnknownAPITypeException {
		this.session = TenantAPIAccessor.getLoginAPI()
				.login(userName, password);