Chapter 6. Creating a self-contained Red Hat Process Automation Manager Spring Boot JAR file You can create a single self-contained Red Hat Process Automation Manager Spring Boot JAR file that contains a complete service, including KIE Server and one or more KJAR files. The Red Hat Process Automation Manager Spring Boot JAR file does not depend on any KJAR files loading at runtime. If necessary, the Red Hat Process Automation 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 Process Automation 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> Optional: if you want to be able to configure the KIE Server instance in the JAR file to communicate with a Business Central monitoring instance using WebSockets, make the following changes: Add the following lines to the pom.xml file under the <dependencies> tag: <dependency> <groupId>org.kie.server</groupId> <artifactId>kie-server-controller-websocket-client</artifactId> <version>USD{version.org.kie}</version> </dependency> WebSockets communication with a Business Central monitoring instance is supported in all cases, including running the instance on Red Hat OpenShift Container Platform. In the <BUSINESS-APPLICATION>/<BUSINESS-APPLICATION>-service/src/main/resources/application.properties file, add or change the following properties: 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. To configure KIE Server to connect to a Business Central monitoring instance using WebSockets and run the image, enter the following command: In this command, replace the following values: <LOCATION> with the fully qualified host name for accessing your service. Business Central monitoring accesses the service to retrieve process information and displays a URL for the service with this host name <PORT> with the port for accessing your service, for example, 8090 <BC-HOSTNAME> with the fully qualified name of the Business Central monitoring instance <BC-PORT> with the port of the Business Central Monitoring instance, for example, 8080 <USER> with the username of a user configured on the Business Central monitoring instance <PASSWORD> with the password of the user configured on the Business Central monitoring instance <FILENAME> with the name of the JAR file Note This configuration uses unsecured HTTP communication for your service. If you configure your Spring Boot business application with a valid SSL certificate, you can replace http: with https: to use secure HTTPS communication. For more information about configuring SSL on Spring Boot, see Spring Boot documentation . Note If you want to view process information from Business Central monitoring, you must ensure that the user that is logged into Business Central can also be authenticated with your service using the same password.

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>
<dependency> <groupId>org.kie.server</groupId> <artifactId>kie-server-controller-websocket-client</artifactId> <version>USD{version.org.kie}</version> </dependency>
kieserver.location=USD{org.kie.server.location} kieserver.controllers=USD{org.kie.server.controller}
mvn install
java -jar <FILENAME>.jar
java -Dorg.kie.server.location=http://<LOCATION>:<PORT>/rest/server -Dorg.kie.server.controller=ws://<BC-HOSTNAME>:<BC-PORT>/websocket/controller -Dorg.kie.server.controller.user=<USER> -Dorg.kie.server.controller.pwd=<PASSWORD> -jar <FILENAME>.jar