Tutorial 4: Deploying Custom KJAR in a Remote Project - redhat-consulting/jbpm-ee GitHub Wiki

Watch the video

In this tutorial you will learn how to create a custom KJAR using the provided jbpm-ee-kjar-archetype and use it in a new remote application.

##Prerequisites:##

In order to be able to complete this tutorial, please follow guide to install the jBPM Eclipse Plugin.

##Create KJAR Application Based on Archetype##

Create an application kjar-app created from jbpm-ee-kjar-archetype.

Let's study the layout of the kjar-app in order to modify and deploy our own. We'll have to modify the files that are in bold.

kjar-app
├── pom.xml
└── src
    └── main
        ├── java
        │   └── my
        │       └── test
        │           ├── LoanOrder.java
        │           └── TestHandler.java
        └── resources
            ├── META-INF
            │   ├── WorkDefinitions.wid
            │   ├── drools.rulebase.conf
            │   ├── kmodule.info
            │   └── kmodule.xml
            ├── testTaskProcess.bpmn2
            └── testWorkItemProcess.bpmn2

Once we are finished with modifications to the kjar-app we need to tell maven to compile and install the new KJAR artifact into the local maven repository.

Modify the WorkDefinitions.wid file and designate your work item handler class, the class has to implement the WorkItemHandler interface. The file drools.rulebase.conf should have only one entry in it which points to the location of the WorkDefinitions.wid file.

drools.rulebase.conf

drools.workDefinitions=WorkDefinitions.wid

WorkDefinitions.wid

[
  [
    "name" : "Custom Handler",
    "displayName" : "Custom Handler",
    "defaultHandler" : "my.test.TestHandler",
    "dependencies" : [
    ]
  ]
]

Let's duplicate the my.test.Testhandler class, name it my.test.MyHandler, and register it in WorkDefinitions.wid. When we are finished, it should look similar to:

edited WorkDefinitions.wid

[
  [
    "name" : "Custom Handler",
    "displayName" : "Custom Handler",
    "defaultHandler" : "my.test.TestHandler",
    "dependencies" : [
    ]
  ],
  [
    "name" : "My Handler",
    "displayName" : "My Handler",
    "defaultHandler" : "my.test.MyHandler",
    "dependencies" : [
    ]
  ]
]

Open testWorkItemProcess.bpmn2 and add a newly created My Handler using the BPMN2 Process Editor.

After you've modified the KJAR, let's install it into the local maven repository. Navigate to the root of the KJAR project and issue:

mvn clean install -DskipTests=true

##Modify the Remote App to Use the New KJAR##

In order to use the new KJAR from our local maven repository, we need to make some changes to the remote-app. Namely, we need to modify:

  1. pom.xml
  2. BaseTest.java
  3. BaseEJBTest.java

pom.xml The project object model descriptor file needs to have it's dependencies updated. We need to replace the jbpm-ee-kjar-sample** dependency with the newly create KJAR artifact. Thus for this example the following dependency is the replacement:

<dependency>
    <groupId>my.test</groupId>
    <artifactId>kjar-app</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>

The the import declaration of the LoanOrder class needs to reflect the newly created KJAR's package in both BaseTest.java, and BaseEJBTest.java.

BaseTest.java lines 34-39 need to be altered to refelect the new KJAR's groupId, artifactId, and version.

protected static final KieReleaseId taskTestReleaseId = new KieReleaseId("org.jbpm.jbpm-ee", "jbpm-ee-kjar-sample", "1.0.0-SNAPSHOT");
protected static final String taskTestProcessId = "testTaskProcess.bpmn2";

protected static final KieReleaseId loanTestReleaseId = new KieReleaseId("org.jbpm.jbpm-ee", "jbpm-ee-kjar-sample", "1.0.0-SNAPSHOT");
protected static final String loanTestProcessId = "testWorkItemProcess.bpmn2";

After the change the lines should look similar to:

protected static final KieReleaseId taskTestReleaseId = new KieReleaseId("my.test", "kjar-app", "1.0-SNAPSHOT");
protected static final String taskTestProcessId = "testTaskProcess.bpmn2";
	
protected static final KieReleaseId loanTestReleaseId = new KieReleaseId("my.test", "kjar-app", "1.0-SNAPSHOT");
	protected static final String loadTestProcessId = "testWorkItemProcess.bpmn2";

We are ready to compile and deploy the Remote Application to test our new KJAR.

⚠️ **GitHub.com Fallback** ⚠️