Last week, I showed you how to get a ‘BPMN 2.0 Hello World’ up and running with the latest release of Activiti. Today, we’ll take the very same example a step further and make it run on MySQL and mavenize it all.
Interested in just the code? Just scroll down to the bottom of the post or click here.
The required stuff remains the same: Eclipse (or any other IDE) with a Maven plugin (I’m using m2eclipse), Java and Ant.
We’re just creating a vanilla Maven project. I’ve used the Eclipse wizard (New -> Maven Project), but some commandline-magic should also do the trick.The end result should look like this in Eclipse:

To run our Hello World example on MySQL, we’ll need two dependencies:
Accordingly, the pom.xml looks like this:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>be.jorambarrez.tutorial</groupId>
<artifactId>helloworld</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-engine</artifactId>
<version>5.0.alpha4</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.13</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>activiti.repo</id>
<url>http://maven.alfresco.com/nexus/content/repositories/activiti/</url>
</repository>
</repositories>
</project>
The Hello world process is the same as the one we’ve used in the previous article.

The corresponding XML also remains the same. Call it hello-world.bpmn20.xml and add it to src/main/resources.
<?xml version="1.0" encoding="UTF-8"?>
<definitions id="definitions"
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
targetNamespace="http://www.activiti.org/bpmn2.0">
<process id="helloWorld">
<startEvent id="start" />
<sequenceFlow id="flow1" sourceRef="start" targetRef="script" />
<scriptTask id="script" name="HelloWorld" scriptFormat="groovy">
<script>
System.out.println("Hello world")
</script>
</scriptTask>
<sequenceFlow id="flow2" sourceRef="script" targetRef="theEnd" />
<endEvent id="theEnd" />
</process>
</definitions>
To run the process, we’ll be using the same main method as in the original article: bootstrap the engine, deploy the process and run it:
// Bootstrap
ProcessEngine processEngine = new DbProcessEngineBuilder()
.configureFromPropertiesResource("activiti.properties")
.buildProcessEngine();
ProcessService processService = processEngine.getProcessService();
// Deployment
processService.createDeployment()
.addClasspathResource("hello-world.bpmn20.xml")
.deploy();
// Run
processService.startProcessInstanceByKey("helloWorld");
The only thing that’s left to do, is add an activiti.properties file to src/main/resources that now points to a MySQL database. Alternatively, you could also use the cfg.create Ant target which is in the setup script of the Activiti distribution (see previous article).
database=mysql
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://192.168.1.102:3306/activiti
jdbc.username=activiti
jdbc.password=activiti
db.schema.strategy=create
Note that we’re setting the schema creation strategy to ‘create‘, since want to create the schema the first time we run our code. If you want to rerun your code afterwards, be sure to change it it ‘check-version‘.
Also, don’t forget to create the schema ‘activiti’ in MySQL and to add the user ‘activiti’ with enough permissions in MySQL.
Now just run it. The output should be non-surprising:

With that difference that we now actually are running on the MySQL database! See the proof on the following picture:

The source for this tutorial can be downloaded as a ZIP file here. Just import it into Eclipse, point it your MySQL config and enjoy the ride!
Any plans to publish the Activiti artifacts to the Maven central repository?
They are currently published against the Alfresco maven repo. I wouldnt know how to get those to the central repo …
Hi,
I have followed the instructions to connect mysql database
I am getting follwing error
J���
5.5.15�°���Ep&ia,TB�ÿ÷�€����������,WPmS7X7JN)#�mysql_native_password�!��ÿ„#08S01Got packets out of order
can anyone please help me out,
i neeed to integraten this workflow to coming project
Thanks in advance