JEE 7 Activiti integration


To enable Activiti in our JEE project the following steps are needed:

  1. Add the maven dependencies — include spring-context
  2. Add log4j configuration
  3. Add the activiti configuration for CDI integration activiti.cfg.xml
  4. Add your first activiti workflow
  5. Add an activiti compatible data source to your container
  6. Deploy and run it

Git Project.

Eclipse Plugin

To install the activiti designer just add the following update site to eclipse: for more details just check the documentation.

Add activity maven dependencies

For JEE we want not only to add the normal dependencies for the core lib but also the CDI integration which allows us later on to access our CDI or EJB beans. In addition, we need one more dependency to have the JNDI bean.

<!-- activiti --> 
<!-- to get org.springframework.jndi.JndiObjectFactoryBean, same version as used by activiti --> 
<!-- Needed to see the log --> 

Add log4j configuration

Before we start with activiti we should add the log4j.xml configuration into src/main/resources which would allow us to see any error in activiti, otherwise, we are blind.

<?xml version="1.0" encoding="UTF-8" ?> 
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> 
<log4j:configuration debug="true" xmlns:log4j=''> 
  <appender name="console" class="org.apache.log4j.ConsoleAppender"> 
    <layout class="org.apache.log4j.PatternLayout"> 
      <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" /> 
    <level value="INFO" /> <appender-ref ref="console" /> 

Add activiti configuration

Add to the src/main/resources folder the default activiti.cfg.xml configuration which is picked up automatically by the activiti CDI integration to create the process engine.

Note: We set here the TransactionManager and the ThreadFactory to ensure threads and the transaction is managed by the JEE container. You may also provide the executor which is configured in the JEE container by you. As the ManagedAsyncJobExecutor is just creating a ThreadPoolExecutor under the hood.
<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="" xmlns:xsi="" xsi:schemaLocation=""> 
  <!-- lookup the JTA-Transaction manager --> 
  <bean id="transactionManager" class="org.springframework.jndi.JndiObjectFactoryBean"> 
    <property name="jndiName" value="java:appserver/TransactionManager" /> 
    <property name="resourceRef" value="true" /> 
  <!-- using the JEE container thread factory for the managed executor service --> 
  <bean id="asyncExecutor" class="org.activiti.engine.impl.asyncexecutor.ManagedAsyncJobExecutor"> 
    <property name="threadFactory"> 
      <bean class="org.springframework.jndi.JndiObjectFactoryBean"> 
        <property name="jndiName" value="java:comp/DefaultManagedThreadFactory" /> 
        <property name="resourceRef" value="true" /> 
  <!-- process engine configuration --> 
  <bean id="processEngineConfiguration" class="org.activiti.cdi.CdiJtaProcessEngineConfiguration"> 
    <property name="dataSourceJndiName" value="jdbc/postgresql" /> 
    <property name="transactionManager" ref="transactionManager" /> 
    <property name="asyncExecutor" ref="asyncExecutor" /> 
    <!-- using externally managed transactions --> 
    <property name="transactionsExternallyManaged" value="true" /> 
    <!-- will create the activiti DB schema automatically as needed --> 
    <property name="databaseSchemaUpdate" value="true" /> 

Deploy a workflow

Overall where to ways to deploy your workflows. Either using XML or programmatically. Here I will use the last to demonstrate the injection and usage in a very simple (not production-ready) way:

public class SampleProcessDeployerBA {

    @Inject RepositoryService repositoryService;

    void start() {
        // this will deploy the same process over and over again ...
        Deployment deploy = repositoryService.createDeployment()
                .key("SampleProcess") // note this has no effect, the ID of the bpmn file is used "myProcess"
        System.out.println("Deployed process ID: " + deploy.getId() + " KEY " + deploy.getKey());

Start a workflow

Note: The process ID is defined in the process bpmn file.
@Named // that activiti finds this EJB
@Singleton // show that this is a singleton
public class HelloWorldBF {
    @Inject RuntimeService runtimeService;

    public void startProcess() {
        // use here the id you defined in the process designer
        ProcessInstance process = runtimeService.startProcessInstanceByKey("myProcess");
        System.out.println("Process " + process.getName() + " started with ID: " + process.getId());

Activiti support currently following DB

Add to your JEE container one JNDI data source of one of the following supported database types. In this sample we name it jdbc/activiti.

Note: The default Sample DB of Payara is a Apache Derby DB and is not supported by Activiti.

This list is taken from version 6.0.

  • H2
  • HSQL
  • DB2
Information:   2017-08-31 20:49:49 ERROR ProcessEngines:169 - Exception while initializing process engine: couldn't deduct database type from database product name 'Apache Derby'
org.activiti.engine.ActivitiException: couldn't deduct database type from database product name 'Apache Derby'
	at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.initDatabaseType(
	at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.initDataSource(
	at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.init(
	at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(
	at org.activiti.engine.ProcessEngines.buildProcessEngine(
	at org.activiti.engine.ProcessEngines.initProcessEngineFromResource(
	at org.activiti.engine.ProcessEngines.init(
	at org.activiti.engine.ProcessEngines.getProcessEngine(

Paul Sterl has written 52 articles

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>