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 KIE 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 Maven project that contains Red Hat Decision Manager business assets.
-
KIE 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.44.0.Final-redhat-00006). 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.9.1.redhat-00003</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?.
(Optional) If your project contains Decision Model and Notation (DMN) assets, also add the following dependency in the
pom.xmlfile to enable DMN executable models. DMN executable models enable DMN decision table logic in DMN projects to be evaluated more efficiently.<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:
mvn clean installFor 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.
注記If the rule assets in your Maven project are not built from an executable rule model by default, verify that the following dependency is in the
pom.xmlfile of your project and rebuild the project:<dependency> <groupId>org.drools</groupId> <artifactId>drools-model-compiler</artifactId> <version>${rhdm.version}</version> </dependency>This dependency is required for rule assets in Red Hat Decision Manager to be built from executable rule models by default. This dependency is included as part of the Red Hat Decision Manager core packaging, but depending on your Red Hat Decision Manager upgrade history, you may need to manually add this dependency to enable the executable rule model behavior.
For more information about executable rule models, see 「Executable rule models」.
After you successfully build and test the project locally, deploy the project to the remote Maven repository:
mvn deploy