3.2. Packaging and deploying a Red Hat Decision Manager project in Maven
If you want to deploy a Maven project outside of Business Central to a configured Decision Server, you can edit the project pom.xml file to package your project as a KJAR file and add a kmodule.xml file with the KIE base and KIE session configurations for the assets in your project.
Prerequisites
- You have a Mavenized project that contains Red Hat Decision Manager business assets.
-
Decision Server is installed and
kie-serveruser access is configured. For installation options, see Planning a Red Hat Decision Manager installation.
Procedure
In the
pom.xmlfile of your Maven project, set the packaging type tokjarand add thekie-maven-pluginbuild component:<packaging>kjar</packaging> ... <build> <plugins> <plugin> <groupId>org.kie</groupId> <artifactId>kie-maven-plugin</artifactId> <version>${rhdm.version}</version> <extensions>true</extensions> </plugin> </plugins> </build>The
kjarpackaging type activates thekie-maven-plugincomponent to validate and pre-compile artifact resources. The<version>is the Maven artifact version for Red Hat Decision Manager currently used in your project (for example, 7.26.0.Final-redhat-00005). These settings are required to properly package the Maven project for deployment.注記Instead of specifying a Red Hat Decision Manager
<version>for individual dependencies, consider adding the Red Hat Business Automation bill of materials (BOM) dependency to your projectpom.xmlfile. The Red Hat Business Automation BOM applies to both Red Hat Decision Manager and Red Hat Process Automation Manager. When you add the BOM files, the correct versions of transitive dependencies from the provided Maven repositories are included in the project.Example BOM dependency:
<dependency> <groupId>com.redhat.ba</groupId> <artifactId>ba-platform-bom</artifactId> <version>7.5.1.redhat-00001</version> <scope>import</scope> <type>pom</type> </dependency>For more information about the Red Hat Business Automation BOM, see What is the mapping between Red Hat Decision Manager and the Maven library version?.
Add the following dependencies to the
pom.xmlfile to generate an executable rule model from your rule assets:-
drools-canonical-model: Enables an executable canonical representation of a rule set model that is independent from Red Hat Decision Manager -
drools-model-compiler: Compiles the executable model into Red Hat Decision Manager internal data structures so that it can be executed by the decision engine
<dependency> <groupId>org.drools</groupId> <artifactId>drools-canonical-model</artifactId> <version>${rhdm.version}</version> </dependency> <dependency> <groupId>org.drools</groupId> <artifactId>drools-model-compiler</artifactId> <version>${rhdm.version}</version> </dependency>Executable rule models are embeddable models that provide a Java-based representation of a rule set for execution at build time. The executable model is a more efficient alternative to the standard asset packaging in Red Hat Decision Manager and enables KIE containers and KIE bases to be created more quickly, especially when you have large lists of DRL (Drools Rule Language) files and other Red Hat Decision Manager assets.
For more information about executable rule models, see Designing a decision service using DRL rules.
To enable Decision Model and Notation (DMN) executable models for DMN assets in your project (if applicable), also add the
kie-dmn-coredependency in thepom.xmlfile:<dependency> <groupId>org.kie</groupId> <artifactId>kie-dmn-core</artifactId> <scope>provided</scope> <version>${rhdm.version}</version> </dependency>-
In the
~/resourcesdirectory of your Maven project, create aMETA-INF/kmodule.xmlmetadata file with at least the following content:<?xml version="1.0" encoding="UTF-8"?> <kmodule xmlns="http://www.drools.org/xsd/kmodule"> </kmodule>This
kmodule.xmlfile is a KIE module descriptor that is required for all Red Hat Decision Manager projects. You can use the KIE module to define one or more KIE bases and one or more KIE sessions from each KIE base.For more information about
kmodule.xmlconfiguration, see 「Configuring a KIE module descriptor file」.In the relevant resource in your Maven project, configure a
.javaclass to create a KIE container and a KIE session to load the KIE base:import org.kie.api.KieServices; import org.kie.api.runtime.KieContainer; import org.kie.api.runtime.KieSession; public void testApp() { // Load the KIE base: KieServices ks = KieServices.Factory.get(); KieContainer kContainer = ks.getKieClasspathContainer(); KieSession kSession = kContainer.newKieSession(); }In this example, the KIE container reads the files to be built from the class path for a
testAppproject. TheKieServicesAPI enables you to access all KIE building and runtime configurations.You can also create the KIE container by passing the project
ReleaseIdto theKieServicesAPI. TheReleaseIdis generated from theGroupId,ArtifactId, andVersion(GAV) values in the projectpom.xmlfile.import org.kie.api.KieServices; import org.kie.api.builder.ReleaseId; import org.kie.api.runtime.KieContainer; import org.kie.api.runtime.KieSession; import org.drools.compiler.kproject.ReleaseIdImpl; public void testApp() { // Identify the project in the local repository: ReleaseId rid = new ReleaseIdImpl("com.sample", "my-app", "1.0.0"); // Load the KIE base: KieServices ks = KieServices.Factory.get(); KieContainer kContainer = ks.newKieContainer(rid); KieSession kSession = kContainer.newKieSession(); }In a command terminal, navigate to your Maven project directory and run the following command to build the project from an executable model:
mvn clean install -DgenerateModel=<VALUE>The
-DgenerateModel=<VALUE>property enables the project to be built as a model-based KJAR instead of a DRL-based KJAR, so that rule assets are built in an executable rule model.Replace
<VALUE>with one of three values:-
YES: Generates the executable model corresponding to the DRL files in the original project and excludes the DRL files from the generated KJAR. -
WITHDRL: Generates the executable model corresponding to the DRL files in the original project and also adds the DRL files to the generated KJAR for documentation purposes (the KIE base is built from the executable model regardless). -
NO: Does not generate the executable model.
Example build command:
mvn clean install -DgenerateModel=YESFor DMN executable models, run the following command:
mvn clean install -DgenerateDMNModel=YESIf the build fails, address any problems described in the command line error messages and try again to validate the files until the build is successful.
-
After you successfully build and test the project locally, deploy the project to the remote Maven repository:
mvn deploy