Chapter 4. Hello World Rule Example
Hello World project with a simple business rule.
- Create a repository in the Artifact repository.
- Create a project.
- Create a rule.
- Create a knowledgebase.
- Build and deploy the project.
- Create a Maven project to fire the rule.
4.1. Create Your First Rule Using Business Central
Ensure that you have successfully installed JBoss BRMS and Maven before you run this simple rule example using Business Central interface.
Procedure 4.1. Create and Execute your First Rule using Business Central
Log into Business Central
- On the command line, change into the
$SERVER_HOME/bin/directory and execute the following command:- for Unix environment:
./standalone.sh
- for Windows environment:
./standalone.bat
- Once your server is up and running, open the following address in a web browser:
http://localhost:8080/business-central
This opens the Business Central login page. - Log into the Business Central with the user credentials created during installation.
Create a repository structure and create a project under it
- On the main menu of Business Central, go to → .
- Click → , then click .
- In the displayed Add New Organizational Unit dialog box, define the unit properties. For example:
- Name: EmployeeWage
- Owner: Employee
Click . - On the perspective menu, click → .
- In the displayed Create Repository dialog box, define the repository properties. For example:
- Repository Name: EmployeeRepo
- Organizational Unit: EmployeeWage
Click . - Go to → .
- In the Project Explorer, under the organizational unit drop-down box, select
EmployeeWage, and in the repository drop-down box selectEmployeeRepo. - On the perspective menu, go to → .
- In the displayed Create new Project dialog box, provide a name (for example,
MyProject) for your project properties and click . - In the New Project dialog box, define the maven properties of the project. For example:
- Group ID: org.brms
- Artifact ID: MyProject
- Version ID: 1.0.0
Click .
Create a fact model
- On the perspective menu, go to → .
- In the displayed Create new Data Object dialog box, provide the values for object name and package. For example:
- Data Object: Person
- Package: org.brms.myproject
Click . - In the displayed Person window of the newly created
Persondata object, click to open the New field dialogue. Add a variable name in the Id field, select data type for the variable in the Type field, and click until you have defined all the necessary variables. For example:- Id: firstNameType: String
- Id: lastNameType: String
- Id: hourlyRateType: Integer
- Id: wageType: Integer
Click for the last variable and then .
Create a rule
- On the perspective menu, click → .
- In the Create new dialog box, provide the name and package name of your rule file. For example:
- DRL file name:
MyRule - Package: org.brms.myproject
Click . - In the displayed DRL editor with the
MyRule.drlfile, write your rule as shown below:package org.brms.myproject; rule "MyRule" when Person(hourlyRate*wage > 100) Person(name : firstName, surname : lastName) then System.out.println( "Hello" + " " + name + " " + surname + "!" ); System.out.println( "You are rich!" ); end
- Click .
Rules are simple when-then statements stored in DRL files. This example has two conditions:Person(hourlyRate*wage > 100)
Person(name : firstName, surname : lastName)
The first line evaluates a logical condition. The second line searches for an instance of the data object Person and saves its attributes, that is, the firstName and lastName into variables used in the second part of the rule.If the conditions are met, the then part of the rule executes. In this example, two lines will be printed out in the JBoss BRMS command line.Create a Knowledge Base
Following steps demonstrate how to create your own knowledge base. For more information about KieSession, see Chapter 16.2.3 from the Red Hat JBoss BPM Suite Development Guide.- Click .
- Navigate to the drop-down menu and click → .
- Click and enter the name of your knowledge base. For this example, enter:
myBase. - Click
- Click under Packages.
- In this step, you are specifying which packages should your knowledge base include. In this example, we want all the packages. Therefore, enter
*(an asterisk). - Click under Knowledge Sessions.
- Enter the name of your session. For example,
mySession. Check and select thestatelessstate. - Click in the top right corner.
Build and deploy your rule
- Click and then click .A green notification appears in the upper part of the screen informing you that the project has been built and deployed successfully to the Execution Server.
Note
In case a red notification appears, informing you that the build has failed, you will be presented with information about the build failure in the JBoss BRMS console. This is crucial information in case of troubleshooting your application. Make sure you have saved all assets before attempting to build your project.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.