Chapter 6. Creating a self-contained Red Hat Decision Manager Spring Boot JAR file You can create a single self-contained Red Hat Decision Manager Spring Boot JAR file that contains a complete service, including KIE Server and one or more KJAR files. The Red Hat Decision Manager Spring Boot JAR file does not depend on any KJAR files loading at runtime. If necessary, the Red Hat Decision Manager Spring Boot JAR file can contain multiple versions of the same KJAR file, including modules. These KJAR files can have the same artifactID and groupID attribute values, but have different version values. The included KJAR files are separated from any JAR files in the BOOT-INF/lib directory to avoid class loader collisions. Each KJAR classpath container file is isolated from other KJAR classpath container files and does not rely on the Spring Boot class loader. Prerequisites You have an existing Red Hat Decision Manager Spring Boot project. You have completed development of one or more KJAR files for the project. Procedure Build all KJAR files for the project. In the default business application, the KJAR source is contained in the <BUSINESS-APPLICATION>/<BUSINESS-APPLICATION>-kjar directory, where BUSINESS-APPLICATION is the name of the business application. Your project might include other KJAR source directories. To build the KJAR files, for every KJAR source directory, complete the following steps: Change to the KJAR source directory. Enter the following command: This command builds the KJAR file and places it into the local Maven repository. By default, this repository is located in the ~/.m2/repo directory. In the <BUSINESS-APPLICATION>/<BUSINESS-APPLICATION>-service/src/main/resources directory, add the following property to your Spring Boot application application.properties file: When this property is set to true , KIE Server uses the class loader used by the container to load KJAR files and their dependencies. Complete one of the following actions to ensure that KIE Server loads the necessary KJAR modules: To configure KIE Server to scans and deploy all KJAR modules available in the Spring Boot application, add the following property to the application.properties file: When this property is set to true , KIE Server deploys all KJAR modules available in the application, whether they are declared programmatically or through the Maven plug-in. This option is the simplest method to include all KJAR modules. However, it has two drawbacks: The application sets all container IDs and aliases automatically, based on the group, artifact, and version (GAV) of every KJAR module. You cannot set a custom container ID or alias for a KJAR module. At startup time, the application scans the JAR file and the class path for KJAR modules. Therefore, the duration of startup might be increased. To avoid these drawbacks, you can configure every KJAR module individually using the application.properties file or using Java source code, as described in one of the following options. To configure every KJAR module individually using the application.properties file, for each of the KJAR modules that you want to include in the service, add the following properties to the application.properties file: Replace the following values: <n> : A sequential number: 0 for the first KJAR module, 1 for the second module, and so on <container> : The container ID for the KJAR module <alias> : The alias for the KJAR module <artifact> : The artifact ID for the KJAR module <group> : The group ID for the KJAR module <version> : The version ID for the KJAR module The following example configures two versions of the Evaluation KJAR module: To configure every KJAR module individually using Java source code, create a class in your business application service, similar to the following example: @Configuration public class KieContainerDeployer { @Bean public KieContainerResource evaluation_v1() { KieContainerResource container = new KieContainerResource("evaluation_v1", new ReleaseId("com.myspace", "Evaluation", "1.0.0-SNAPSHOT"), STARTED); container.setConfigItems(Arrays.asList(new KieServerConfigItem(KieServerConstants.PCFG_RUNTIME_STRATEGY, "PER_PROCESS_INSTANCE", "String"))); return container; } @Bean public KieContainerResource evaluation_v2() { KieContainerResource container = new KieContainerResource("evaluation_v2", new ReleaseId("com.myspace", "Evaluation", "2.0.0-SNAPSHOT"), STARTED); container.setConfigItems(Arrays.asList(new KieServerConfigItem(KieServerConstants.PCFG_RUNTIME_STRATEGY, "PER_PROCESS_INSTANCE", "String"))); return container; } } For every KJAR module that you want to include, create a KieContainerResource bean in this class. The name of the bean is the container name, the first parameter of KieContainerResource() is the alias name, and the parameters of ReleaseId() are the group ID, artifact ID, and version ID of the KJAR module. Optional: If your business application will run in an Red Hat OpenShift Container Platform pod or in any other environment where the current directory is not writable, add the spring.jta.log-dir property to the application.properties file and set it to a writable location. For example: This parameter sets the location for the transaction log. In the <BUSINESS-APPLICATION>/<BUSINESS-APPLICATION>-service directory, add the following Maven plug-in in the Spring Boot pom.xml file where <GROUP_ID> , <ARTIFACT_ID> , and <VERSION> are the group, artifact, and version (GAV) of a KJAR artifact that your project uses. You can find these values in the pom.xml file that is located in the KJAR source directory. Note You can add more than one version of an artifact. <build> <plugins> <plugin> <groupId>org.kie</groupId> <artifactId>kie-maven-plugin</artifactId> <version>USD{version.org.kie}</version> <executions> <execution> <id>copy</id> <phase>prepare-package</phase> <goals> <goal>package-dependencies-kjar</goal> </goals> </execution> </executions> <configuration> <artifactItems> <artifactItem> <groupId><GROUP_ID></groupId> <artifactId><ARTIFACT_ID></artifactId> <version><VERSION></version> </artifactItem> </artifactItems> </configuration> </plugin> <plugins> <build> The artifacts required to run the KJAR will be resolved at build time. The following example adds two version of the Evaluation artifact: <build> <plugins> <plugin> <groupId>org.kie</groupId> <artifactId>kie-maven-plugin</artifactId> <version>USD{version.org.kie}</version> <executions> <execution> <id>copy</id> <phase>prepare-package</phase> <goals> <goal>package-dependencies-kjar</goal> </goals> </execution> </executions> <configuration> <artifactItems> <artifactItem> <groupId>com.myspace</groupId> <artifactId>Evaluation</artifactId> <version>1.0.0-SNAPSHOT</version> </artifactItem> <artifactItem> <groupId>com.myspace</groupId> <artifactId>Evaluation</artifactId> <version>2.0.0-SNAPSHOT</version> </artifactItem> </artifactItems> </configuration> </plugin> </plugins> </build> To build the self-contained Spring Boot image, enter the following command in the <BUSINESS-APPLICATION>/<BUSINESS-APPLICATION>-service directory: Optional: to run the self-contained Spring Boot image, locate the JAR file in the target subdirectory and enter the following command: In this command, replace <FILENAME> with the name of the JAR file.

Commands:
mvn install
kieserver.classPathContainer=true
kieserver.autoScanDeployments=true
kieserver.deployments[<n>].containerId=<container> kieserver.deployments[<n>].alias=<alias> kieserver.deployments[<n>].artifactId=<artifact> kieserver.deployments[<n>].groupId=<group> kieserver.deployments[<n>].version=<version>
kieserver.deployments[0].alias=evaluation_v1 kieserver.deployments[0].containerId=evaluation_v1 kieserver.deployments[0].artifactId=Evaluation kieserver.deployments[0].groupId=com.myspace kieserver.deployments[0].version=1.0.0-SNAPSHOT kieserver.deployments[1].alias=evaluation_v2 kieserver.deployments[1].containerId=evaluation_v2 kieserver.deployments[1].artifactId=Evaluation kieserver.deployments[1].groupId=com.myspace kieserver.deployments[1].version=2.0.0-SNAPSHOT
@Configuration public class KieContainerDeployer { @Bean public KieContainerResource evaluation_v1() { KieContainerResource container = new KieContainerResource("evaluation_v1", new ReleaseId("com.myspace", "Evaluation", "1.0.0-SNAPSHOT"), STARTED); container.setConfigItems(Arrays.asList(new KieServerConfigItem(KieServerConstants.PCFG_RUNTIME_STRATEGY, "PER_PROCESS_INSTANCE", "String"))); return container; } @Bean public KieContainerResource evaluation_v2() { KieContainerResource container = new KieContainerResource("evaluation_v2", new ReleaseId("com.myspace", "Evaluation", "2.0.0-SNAPSHOT"), STARTED); container.setConfigItems(Arrays.asList(new KieServerConfigItem(KieServerConstants.PCFG_RUNTIME_STRATEGY, "PER_PROCESS_INSTANCE", "String"))); return container; } }
spring.jta.log-dir=/tmp
<build> <plugins> <plugin> <groupId>org.kie</groupId> <artifactId>kie-maven-plugin</artifactId> <version>USD{version.org.kie}</version> <executions> <execution> <id>copy</id> <phase>prepare-package</phase> <goals> <goal>package-dependencies-kjar</goal> </goals> </execution> </executions> <configuration> <artifactItems> <artifactItem> <groupId><GROUP_ID></groupId> <artifactId><ARTIFACT_ID></artifactId> <version><VERSION></version> </artifactItem> </artifactItems> </configuration> </plugin> <plugins> <build>
<build> <plugins> <plugin> <groupId>org.kie</groupId> <artifactId>kie-maven-plugin</artifactId> <version>USD{version.org.kie}</version> <executions> <execution> <id>copy</id> <phase>prepare-package</phase> <goals> <goal>package-dependencies-kjar</goal> </goals> </execution> </executions> <configuration> <artifactItems> <artifactItem> <groupId>com.myspace</groupId> <artifactId>Evaluation</artifactId> <version>1.0.0-SNAPSHOT</version> </artifactItem> <artifactItem> <groupId>com.myspace</groupId> <artifactId>Evaluation</artifactId> <version>2.0.0-SNAPSHOT</version> </artifactItem> </artifactItems> </configuration> </plugin> </plugins> </build>
mvn install
java -jar <FILENAME>.jar