Practical Guide to Using Drools DMN Engine without Kie Server
This article explains the concepts of DMN and Drools, why Drools is chosen, and provides step‑by‑step instructions—including online editing with Kogito and Maven‑free deployment techniques—to run DMN rules in Java projects without relying on a Kie Server.
1 Background Introduction
1.1 What is DMN
DMN (Decision Model and Notation) is a standard for representing business decisions and rules, enabling stakeholders to understand decision processes quickly through visual diagrams and tables.
1.2 Why Use DMN
In the ZhaiZhai Book project, pricing logic became too complex to maintain in pure Java code; DMN provides a visual, editable representation that reduces dependence on developers and improves communication.
1.3 What is Drools
Drools is an open‑source Java rule engine that implements the DMN specification, acting as a concrete implementation of the DMN interface.
1.4 Why Choose Drools
Drools runs on the existing Java environment (zero extra deployment cost), fully supports the highest DMN conformance level, and benefits from an active community and robust tooling.
2 Drools Engine Application
Content based on Drools version 7.61.0; later versions may differ.
2.1 Official Recommended Direct Approach
Deploy a Kie Server to execute DMN rules and use the Drools web workbench for editing, testing, and publishing rules via the Kie Server REST API.
2.2 Limitations in the ZhaiZhai Book Project
The project cannot adopt the official approach because its internal framework does not include JBoss‑based Kie Server, and external dependencies increase operational risk.
3 Practicing Drools Engine without Kie Server
3.1 Online Editing of DMN Rules
Kogito provides an all‑in‑one JavaScript file that enables online BPMN/DMN editing; the project wrapped this script to integrate editing into its backend UI, adding record lists for version control.
3.2 Executing DMN Rules with Drools Engine
Without Kie Server, the engine is invoked directly in code. First, add Drools dependencies, then create and use the engine as shown:
KieServices kieServices = KieServices.Factory.get();
ReleaseId releaseId = kieServices.newReleaseId("com", "my-kjar", "1.0.0");
KieContainer kieContainer = kieServices.newKieContainer(releaseId);
DMNRuntime dmnRuntime = KieRuntimeFactory.of(kieContainer.getKieBase()).get(DMNRuntime.class);
String namespace = "my-namespace";
String modelName = "dmn-model-name";
DMNModel dmnModel = dmnRuntime.getModel(namespace, modelName);
DMNContext dmnContext = dmnRuntime.newContext();
dmnContext.set("inputData", "123");
DMNResult dmnResult = dmnRuntime.evaluateAll(dmnModel, dmnContext);
for (DMNDecisionResult dr : dmnResult.getDecisionResults()) {
log.info("Decision: '" + dr.getDecisionName() + "', Result: " + dr.getResult());
}The DMN model must be packaged in a JAR that the Kie container can resolve via Maven.
3.3 Completing the Process Flow
Since the all‑in‑one JS lacks built‑in validation, the project uses KieContainer.verify() to check rules before saving:
Results verify = kieContainer.verify();
for (Message message : verify.getMessages()) {
log.info(message.getLevel().name() + ": " + message.getText());
}3.4 DLC – Running Drools without Maven
When Maven is unavailable (e.g., on a Spark cluster), the engine can be fed a manually constructed JAR containing the DMN file and required metadata:
// Generate a JAR with kmodule.xml, pom files, and the DMN rule
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
JarOutputStream jos = new JarOutputStream(outputStream);
// kmodule.xml
jos.putNextEntry(new JarEntry("/META-INF/kmodule.xml"));
jos.write("
".getBytes(StandardCharsets.UTF_8));
// pom.properties
jos.putNextEntry(new JarEntry("/META-INF/maven/com.myspace/test/pom.properties"));
jos.write("groupId=com.myspace\nartifactId=test\nversion=1.0.0".getBytes(StandardCharsets.UTF_8));
// pom.xml
jos.putNextEntry(new JarEntry("/META-INF/maven/com.myspace/test/pom.xml"));
jos.write("
...
".getBytes(StandardCharsets.UTF_8));
// DMN file
jos.putNextEntry(new JarEntry("/config/rules/test.dmn"));
jos.write(dmn.getBytes(StandardCharsets.UTF_8));
jos.finish();
ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
KieServices kieServices = KieServices.Factory.get();
KieRepository repository = kieServices.getRepository();
KieModule kieModule = repository.addKieModule(kieServices.getResources().newInputStreamResource(inputStream));
// Use a custom ClassLoader instead of MavenClassLoaderResolver
KieContainer kieContainer = kieServices.newKieContainer(kieModule.getReleaseId(), ProjectClassLoader.findParentClassLoader());This approach eliminates the need for a Maven environment while still allowing the Drools engine to locate and execute the DMN rules.
4 Summary
DMN offers clear advantages: rule updates without code changes, a single codebase for multiple scenarios, visual workflow, and participation from non‑developers. Drawbacks include visual clutter for complex graphs, occasional need for custom code, and slower execution compared to pure Java.
5 References
Drools official site, DMN tutorials, Kogito sandbox, KIE portal, and OMG DMN specifications.
Zhuanzhuan Tech
A platform for Zhuanzhuan R&D and industry peers to learn and exchange technology, regularly sharing frontline experience and cutting‑edge topics. We welcome practical discussions and sharing; contact waterystone with any questions.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.