Embedding JBPM 4.3 in a Grails 1.2.2 Application « Intelligrape Groovy & Grails Blogs

Embedding JBPM 4.3 in a Grails 1.2.2 Application

Posted by Himanshu Seth

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:

  1. Download jbpm from here.
  2. 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 :
  3. Also copy the mail.jar from the jbpm installation directory (${jbpmHome}/lib) to the lib directory of your application.
  4. 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>
  5. Create a class in src/groovy
    package com.jbpm.example
     
    class Printer {
     
     public void printHelloWorld() {
       System.out.println("&lt;----------------&gt;");
       System.out.println("&amp;nbsp;&amp;nbsp; HELLO WORLD!");
       System.out.println("&lt;----------------&gt;");
     }
    }
  6. 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>
  7. 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>
  8. Create the following Spring beans is resources.groovy
    springHelper(org.jbpm.pvm.internal.processengine.SpringHelper) {
            jbpmCfg = "jbpm.cfg.xml"
    }
    processEngine(springHelper:"createProcessEngine")
  9. 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();
  10. 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

  • Share/Bookmark
Tags: ,
This entry was posted on May 14th, 2010 at 11:45 pm and is filed under Grails, System . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

9 Responses to “Embedding JBPM 4.3 in a Grails 1.2.2 Application”

  1. fan says:

    where is jbpm.jar in JBPM 4.3?
    where is your last two code?

  2. himanshu says:

    Hi fan,
    Sorry I was not able to get to your comment earlier. I have updated the post to include the screenshot of the unziped contents of the jbpm4.3 zip file.

  3. sanjeev says:

    Thank you so much for putting this documentation up. I am at my wits-end and completely disappointed with the lack of documentation for jbpm integration with grails.

    I am trying to integrate grails 1.2.2 with jbpm 4.3 on jdk 1.5

    I am having trouble running this example as my grails app keeps restarting. I have a feeling hibernate layer keeps dropping the connection. would you by any chance know why?.

    Also Could you please SPECIFY where step 9 and step 10 go. Where should we put that code in Bootstrap or Controller. One of the readers before has asked this question as well.

    I have looked all over jbpm website and found nothing.

    PLEASE HELP

  4. sanjeev says:

    I resolved the issues where my grails-app keeps restarting.. This was because on of my classes in the src/groovy had improper package declaration. – Some how grails throws no error and keeps restarting the app.

    Now the only question i have is where do we put the code in step 9 and step 10.. Do they go in the Bootstrap on in spring beans?

  5. fabien says:

    I do have the following issue when jbpm.cfg.xml is unchanged from plugin install.

    2010-06-22 19:01:49,976 [main] ERROR [localhost].[/JbpmHelloWorld2] – Exception sending context initialized event to listener instance of class org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘processEngine’: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [protected org.jbpm.api.ProcessEngine org.jbpm.pvm.internal.processengine.SpringHelper.createProcessEngine()] threw exception; nested exception is java.lang.NullPointerException

    And i do have the followiong issue when adding the imports in jbpm.cfg.xml.

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘jbpmTemplate’: Cannot resolve reference to bean ‘jbpmConfiguration’ while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘jbpmConfiguration’: Invocation of init method failed; nested exception is org.jbpm.JbpmException: no ObjectInfo class specified for element ‘import’

    Could anybody help me ?

    I believe that it should be fine to put steps 9 and 10 in a grails Service.

  6. fabien says:

    Hi,

    No need to install previous version of the jbpm plugin.
    Forget my previous post. It is working.

    Cheers.

  7. aziz says:

    Hi,
    Does anyone has a working example for the item below using Grails and JBPM ?
    Workflow with :
    a) Safe forms and Assign Tasks
    b) Reassign Tasks
    c) Forward Tasks after they are done
    d) Email notification
    e) Enable/ Suspended Tasks
    f) Generate Summary of Tasks in Pipeline
    g) Generate history of completed task

    Thanks.

  8. mudou says:

    greate start point!:>

    i walk througth the example and find some errors. however, i solve it finally!

    error 1: Class not found: javax/script/ScriptEngineManager
    solved: copy ${jbpmHome}/lib/livetribe-jsr223.jar to the lib directory of your application.

    error 2: Class org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor can not access a member of class com.jbpm.example.Printer with modifiers “”
    solved: Make the class public. eg: public class Printer{…}

  9. Ramesh says:

    Have you foud a way to use the Grails DataSource?

Leave a Reply