Hi,
In one of our projects, we had a requirement for using some existing Business Process Management tool. JBPM is one such tool that we are evaluating.
Our first step was to run a “Hello World” process from inside the grails application. On searching over the internet, I didn’t find any helpful article/blog on integrating JBPM inside a grails application. However, there were some very good resources on integrating JBPM with a spring application. I found Joram Barrez’s Hello World Example very helpful and was able to integrate using the following steps:
- Download jbpm from here.
- Unzip the contents and copy the jbpm.jar file to the lib directory of your application. The exploded directory has the following files/ folders for version 4.3 :

- Also copy the mail.jar from the jbpm installation directory (${jbpmHome}/lib) to the lib directory of your application.
- Create a process descriptor file in the conf directory (helloWorld.jpdl.xml) with the following code
<process name="helloWorld" xmlns="http://jbpm.org/4.0/jpdl"> <start> <transition to="printHelloWorld"/> </start> <java class="com.jbpm.example.Printer" method="printHelloWorld" name="printHelloWorld"> <transition to="CheckDate"/> <transition to="theEnd"/> </java> <end name="theEnd" /> <state name="CheckDate"> <transition to="printHelloWorld"/> </state> </process>
- Create a class in src/groovy
package com.jbpm.example class Printer { public void printHelloWorld() { System.out.println("<---------------->"); System.out.println("&nbsp;&nbsp; HELLO WORLD!"); System.out.println("<---------------->"); } }
- Create a minimal jBPM config (jbpm.cfg.xml) in the conf directory
<jbpm-configuration> <import resource="jbpm.default.cfg.xml"/> <import resource="jbpm.tx.hibernate.cfg.xml"/> <import resource="jbpm.jpdl.cfg.xml"/> </jbpm-configuration>
- Create a basic Hibernate config called conf/jbpm.hibernate.cfg.xml(I’m using MySql, Still looking for a way on how to use the grails DataSource)
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/testJbpm?autoReconnect=true</property> <property name="hibernate.connection.username">username</property> <property name="hibernate.connection.password">password</property> <property name="hibernate.format_sql">true</property> <property name="hibernate.hbm2ddl.auto">update</property> <mapping resource="jbpm.repository.hbm.xml" /> <mapping resource="jbpm.execution.hbm.xml" /> <mapping resource="jbpm.history.hbm.xml" /> <mapping resource="jbpm.task.hbm.xml" /> <mapping resource="jbpm.identity.hbm.xml" /> </session-factory> </hibernate-configuration>
- Create the following Spring beans is resources.groovy
springHelper(org.jbpm.pvm.internal.processengine.SpringHelper) { jbpmCfg = "jbpm.cfg.xml" } processEngine(springHelper:"createProcessEngine")
- Now lets deploy this process. To deploy a process we will need to inject the processEngine bean
def processEngine;
The code to deploy this process is
RepositoryService repositoryService = processEngine.getRepositoryService(); repositoryService.createDeployment() .addResourceFromClasspath("helloWorld.jpdl.xml") .deploy();
- Lets start an instance of this service :
ExecutionService executionService = processEngine.getExecutionService(); executionService.startProcessInstanceByKey("helloWorld");
This will execute the printHelloWorld method of the Printer class as configured in the process description file.
Hope you find this useful. We are still working on executing more complex processes and will keep posting our learnings.
Your feedback and suggestions are welcome.
Regards
~~Himanshu Seth~~
http://www.IntelliGrape.com
