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>-kjardirectory, whereBUSINESS-APPLICATIONis 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:
mvn install
mvn installCopy to Clipboard Copied! Toggle word wrap Toggle overflow This command builds the KJAR file and places it into the local Maven repository. By default, this repository is located in the
~/.m2/repodirectory.
In the
<BUSINESS-APPLICATION>/<BUSINESS-APPLICATION>-service/src/main/resourcesdirectory, add the following property to your Spring Boot applicationapplication.propertiesfile:kieserver.classPathContainer=true
kieserver.classPathContainer=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow 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.propertiesfile:kieserver.autoScanDeployments=true
kieserver.autoScanDeployments=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow 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.propertiesfile or using Java source code, as described in one of the following options.To configure every KJAR module individually using the
application.propertiesfile, for each of the KJAR modules that you want to include in the service, add the following properties to theapplication.propertiesfile: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[<n>].containerId=<container> kieserver.deployments[<n>].alias=<alias> kieserver.deployments[<n>].artifactId=<artifact> kieserver.deployments[<n>].groupId=<group> kieserver.deployments[<n>].version=<version>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Replace the following values:
-
<n>: A sequential number:0for the first KJAR module,1for 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
EvaluationKJAR module:Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
To configure every KJAR module individually using Java source code, create a class in your business application service, similar to the following example:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow For every KJAR module that you want to include, create a
KieContainerResourcebean in this class. The name of the bean is the container name, the first parameter ofKieContainerResource()is the alias name, and the parameters ofReleaseId()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-dirproperty to theapplication.propertiesfile and set it to a writable location. For example:spring.jta.log-dir=/tmp
spring.jta.log-dir=/tmpCopy to Clipboard Copied! Toggle word wrap Toggle overflow This parameter sets the location for the transaction log.
In the
<BUSINESS-APPLICATION>/<BUSINESS-APPLICATION>-servicedirectory, add the following Maven plug-in in the Spring Bootpom.xmlfile 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 thepom.xmlfile that is located in the KJAR source directory.NoteYou can add more than one version of an artifact.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The artifacts required to run the KJAR will be resolved at build time.
The following example adds two version of the
Evaluationartifact:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: if you want to be able to configure KIE Server to communicate with a Business Central monitoring instance using WebSockets, make the following changes:
Add the following lines to the
pom.xmlfile under the<dependencies>tag:<dependency> <groupId>org.kie.server</groupId> <artifactId>kie-server-controller-websocket-client</artifactId> <version>${version.org.kie}</version> </dependency><dependency> <groupId>org.kie.server</groupId> <artifactId>kie-server-controller-websocket-client</artifactId> <version>${version.org.kie}</version> </dependency>Copy to Clipboard Copied! Toggle word wrap Toggle overflow 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.propertiesfile, add or change the following properties:kieserver.location=${org.kie.server.location} kieserver.controllers=${org.kie.server.controller}kieserver.location=${org.kie.server.location} kieserver.controllers=${org.kie.server.controller}Copy to Clipboard Copied! Toggle word wrap Toggle overflow
To build the self-contained Spring Boot image, enter the following command in the
<BUSINESS-APPLICATION>/<BUSINESS-APPLICATION>-servicedirectory:mvn install
mvn installCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: to run the self-contained Spring Boot image, locate the JAR file in the
targetsubdirectory and enter the following command:java -jar <FILENAME>.jar
java -jar <FILENAME>.jarCopy to Clipboard Copied! Toggle word wrap Toggle overflow 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:
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
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>.jarCopy to Clipboard Copied! Toggle word wrap Toggle overflow 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 fileNoteThis 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:withhttps:to use secure HTTPS communication. For more information about configuring SSL on Spring Boot, see Spring Boot documentation.NoteIf 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.
-