jBPM5 - Hello World!
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 −
Click Next. Give an appropriate name for the first project : "HelloWorld" in our case.
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
Click Next. Click Configure Workspace Settings (marked red in the following screenshot) −
Click the Add button −
Once you click the Add button, the following screen appears. Click "Create a new 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.
The following screen appears. Click the Finish button.
Now, open the Package Explorer view in Eclipse. You will get to see the following screen −
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 −
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.
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 −
To see the entire code written inside the "Hello" event, select the Action property.
The circle marked in red is the edit of the action property. Once you click on Edit −
You can edit this and write the code which you want to execute inside the "Hello" script task. Let us edit it −
Click OK. Now open the ProcessTest.java class and run it as a Java Application. Given below is its output −
The terms used in the ProcessTest.java class are the same used for Drools. The point to note in ProcessTest.java class is −
When you write the code for starting the process, the string passed to startProcess method is the id property when we open the workflow.