2.2. Executing Your First Process


To execute your process, right-click on RuleFlowTest.java and select Run As..., followed by Java Application.
When the process executes, the following output will appear in the Console window:
Hello World
Copy to Clipboard Toggle word wrap
Look at the code of RuleFlowTest class:
package com.sample;

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.logger.KnowledgeRuntimeLogger;
import org.drools.logger.KnowledgeRuntimeLoggerFactory;
import org.drools.runtime.StatefulKnowledgeSession;

/**
 * This is a sample file to launch a process.
 */
public class ProcessTest {

  public static final void main(String[] args) {
    try {
      // load up the knowledge base
      KnowledgeBase kbase = readKnowledgeBase();
      StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
      KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
      // start a new process instance
      ksession.startProcess("com.sample.ruleflow");
      logger.close();
    } catch (Throwable t) {
      t.printStackTrace();
    }
  }

  private static KnowledgeBase readKnowledgeBase() throws Exception {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource("ruleflow.rf"), ResourceType.DRF);
    return kbuilder.newKnowledgeBase();
  }

}
Copy to Clipboard Toggle word wrap
As you can see, the execution process is made up of a number of steps:
  1. Firstly, a knowledge base is created. A knowledge base contains all the knowledge (such as words, processes, rules, and so forth) that are needed by your application. This knowledge base is usually created once, and then reused multiple times. In this case, the knowledge base consists of the sample process only.
  2. Next, a session for interaction with the engine is generated.
    A logger is then added to the session. This records all execution events and make it easier for you to visualize what is happening.
  3. Finally, you can start a new instance of the process by invoking the startProcess(String processId) method on the session. When you do this, your process instance begins to run, resulting in the executions of the Start node, the Action node, and the End node in order. When they finish the process instance will conclude.
Because you added a logger to the session, you can review what happened by looking at the audit log:
Select the Audit View tab on the bottom right of the window, (next to the Console tab.)
Click on the Open Log button (the first one on the right) and navigate to the newly created test.log file (in your project directory.)

Note

If you are not sure where this project directory is located, right-click on it and you will find the location listed in the Resource section
A tree view will appear. This shows the events that occurred at run-time. Events that were executed as the direct result of another event are shown as the children of that event.
This log shows that after starting the process, the Start node, the Action node and the End node were triggered, in that order, after which the process instance was completed.
You can now start to experiment by designing your own process by modifying the example. To validate your processes, click on the Check the rule-flow model button (this is the green check box action in the upper tool-bar that appears when you are editing a process.) Processes are also automatically validated when you save them. You can see the debugging information in the Error View.
Back to top
Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Theme

© 2026 Red Hat