English 中文(简体)
jBPM5 - Hello World!
  • 时间:2024-12-22

jBPM5 - Hello World!


Previous Page Next Page  

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

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

Drools Project

Cpck 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

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

Drools Runtime

Cpck the Add button −

Add

Once you cpck the Add button, the following screen appears. Cpck "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 cpck OK.

Installed Drools Runtimes

The following screen appears. Cpck the Finish button.

Finish Button

Now, open the Package Explorer view in Ecppse. 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 cpck 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 psted 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.

Cpck 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 cpck 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

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

Java Apppcation

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