Gettings started with JBoss jBPM5

In my journey through all the modules of Drools (Expert, Fusion, Planner), I also visit jBPM (fomerly known as Drools Flow). In this tutorial we just get started with Netbeans and a simple hello world project and focusing on the basics, such as required libraries and running within the Netbeans IDE.
Netbeans is not as close to the BPM community as Eclipse, there is no plugin available, the SOA project is abandoned (I guess). But using Netbeans as our IDE, I will not move over to Eclipse, but see how I can run and debug with Netbeans but still use some Eclipse features.

About BPMN:

The JBoss engine execute BPMN files, we can create this files manually or using one of the visual tools. For the basic understanding you should create a simple BPMN by hand to learn a bit about the notation.

Lets create the most simple BPM flow possible:

Pre-Requisites:

Tutorial:

  • Create a simple java application HellojBPM5

    New java application

  • Add the library files from the previous project, as well the additional jBPM5 libraries
    – jbpm-bpmn2-5.2.0.Final.jar
    – jbpm-flow-builder-5.2.0.Final.jar
    – jbpm-flow-5.2.0.Final.jar

    Libraries

  • Create a bpmn file
    The most simple process consisting of nothing but a start and end-event and a simple task (script).

    <?xml version="1.0" encoding="UTF-8"?>
    <definitions id="Definition"
                 targetNamespace="http://www.jboss.org/drools"
                 typeLanguage="http://www.java.com/javaTypes"
                 expressionLanguage="http://www.mvel.org/2.0"
                 xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd"
                 xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
                 xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"
                 xmlns:di="http://www.omg.org/spec/DD/20100524/DI"
                 xmlns:tns="http://www.jboss.org/drools">
    
      <process processType="Private" isExecutable="true" id="demo.jbpm5.hello" name="Hello World" >
    
        <!-- nodes -->
        <startEvent id="_1" name="StartProcess" />
    
        <scriptTask id="_2" name="Say Hello" >
          <script>System.out.println("Hello World!");</script>
        </scriptTask>
    
        <endEvent id="_3" name="EndProcess" >
            <terminateEventDefinition/>
        </endEvent>
    
        <!-- connections -->
        <sequenceFlow id="_1-_2" sourceRef="_1" targetRef="_2" />
        <sequenceFlow id="_2-_3" sourceRef="_2" targetRef="_3" />
    
      </process>
    
    </definitions>
    
  • Create/Update the main class to read the bpmn file and execute as a process
    I recommend reading the core API chapter of the user manual which describes very well the methods.

    
    package hellojbpm5;
    
    import org.drools.KnowledgeBase;
    import org.drools.builder.KnowledgeBuilder;
    import org.drools.builder.KnowledgeBuilderFactory;
    import org.drools.builder.ResourceType;
    import org.drools.io.ResourceFactory;
    import org.drools.runtime.StatefulKnowledgeSession;
    
    public class HellojBPM5 {
    
        public static void main(String[] args) {
    
            KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
            kbuilder.add(ResourceFactory.newClassPathResource("/hellojbpm5/hellojbpm5.bpmn",HellojBPM5.class), ResourceType.BPMN2);
            KnowledgeBase kbase = kbuilder.newKnowledgeBase();
            StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
            ksession.startProcess("demo.jbpm5.hello");
            ksession.dispose();
    
        }
    }
    
  • Runthe application / process

    Project Structure

    Execute process

Outlook:

  • More complex process descriptions
  • Use of a visual editor
  • Further interaction with the process, parameter, etc
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s