jBPM5 - Hello World!


Advertisements

Here in this chapter, we will write our first program "Hello World" using jBPM. Follow the steps given below −

Go to File → New → Drools Project −

New Project

Click Next. Give an appropriate name for the first project : "HelloWorld" in our case.

Drools Project

Click Next. Select the bottom two checkboxes, viz −

  • Add a sample HelloWorld process file to this project
  • Add a sample class for loading and executing HelloWorld process
New Drools Project

Click Next. Click Configure Workspace Settings (marked red in the following screenshot) −

Drools Runtime

Click the Add button −

Add

Once you click the Add button, the following screen appears. Click "Create a new Drools5 Runtime"

Drools5 Runtime

Give the path till the binaries folder where you have downloaded the droolsjbpm-tools-distribution-5.3.0.Final.zip

Then, select the Installed Drools Runtimes and click OK.

Installed Drools Runtimes

The following screen appears. Click the Finish button.

Finish Button

Now, open the Package Explorer view in Eclipse. You will get to see the following screen −

Package Explorer

The ProcessTest.java class is the class to load the ruleflow(rf) file and ruleflow.rf is the basic rule flow created for the HelloWorld project.

Double click on the ruleflow.rf file and you would see the following ruleflow −

Ruleflow

The GREEN circle depicts the start of the workflow, whereas the RED circle is the end of workflow.

The panel depicted on the left-hand side has different components listed which are used in the workflow. Apart from START and END, there are a lot of components which can be used in the workflow and we would be covering them in the next section.

The Hello in between the START and END event is a script task and the name of the script task is Hello. To see what code is written in the script task "Hello", go to Windows → Show View → Other → Properties.

Show View

Note − While working on jBPM, please keep the Properties view open at all times because all the configurations are visible in the properties view only.

Click the OK button. Now, select Hello and you can see the properties of "Hello" event −

Properties of Hello

To see the entire code written inside the "Hello" event, select the Action property.

Action Properties

The circle marked in red is the edit of the action property. Once you click on Edit −

Action Editor

You can edit this and write the code which you want to execute inside the "Hello" script task. Let us edit it −

Action Editor

Click OK. Now open the ProcessTest.java class and run it as a Java Application. Given below is its output −

Java Application

The terms used in the ProcessTest.java class are the same used for Drools. The point to note in ProcessTest.java class is −

ksession.startProcess("com.sample.ruleflow");

When you write the code for starting the process, the string passed to startProcess method is the id property when we open the workflow.

Start Process
Advertisements