Search This Blog

Monday, December 15, 2014

jBPM Process Deployment

Chapter 4. Deploying business archives

A business archive is a collection of files assembled in a jar formatted file. The files in a business archive can be jPDL process files, forms, classes, process image and other process resources.

4.1. Deploying process files and process resources

Process files and process resources have to be deployed in the process repository which is stored in the database.
There is a jBPM ant task to deploy business archives (org.jbpm.pvm.internal.ant.JbpmDeployTask). The JbpmDeployTask can deploy individual process files and business archives. They are deployed directly to the database over a JDBC connection. So it is a requirement that the database is up and running before you can deploy processes.
An example of creating and deploying a business archive can be found in the ant build script (build.xml) in the examples directory of the distribution. Let's look at the relevant parts. First a path is declared that includes the jbpm.jar and all its dependencies.


<path id="jbpm.libs.incl.dependencies">
  <pathelement location="${jbpm.home}/examples/target/classes" />
  <fileset dir="${jbpm.home}">
    <include name="jbpm.jar" />
  </fileset>
  <fileset dir="${jbpm.home}/lib" />
</path>
 
 
The JDBC driver jar(s) for your database should also be included in the path. MySQL, PostgreSQL and HSQLDB are in the distribution. But the Oracle driver you have to download separately from the oracle site since we're not allowed to redistribute that file.
When a business archive is deployed, jBPM scans for all the files with the .jpdl.xml extension in the business archive. All those files will be parsed as jPDL processes and made available to the runtime engine. All other resources in the business archive will also be stored as resources in that deployment and made accessible through InputStream getResourceAsStream(long deploymentDbid, String resourceName); in class RepositoryService
For creating a business archives, the jar task can be used.

<jar destfile="${jbpm.home}/examples/target/examples.bar">
  <fileset dir="${jbpm.home}/examples/src">
    <include name="**/*.jpdl.xml" />
    ...
  </fileset>
</jar>
 
 
Before the jbpm-deploy task can be used it need to be declared like this:

<taskdef name="jbpm-deploy"
    classname="org.jbpm.pvm.internal.ant.JbpmDeployTask"
    classpathref="jbpm.libs.incl.dependencies" />
 
 
Then the ant task can be used like this
<jbpm-deploy file="${jbpm.home}/examples/target/examples.bar" />
 

Table 4.1. jbpm-deploy attributes:
AttributeTypeDefaultRequired?Description
filefileoptionalA file to be deployed. Files ending with .xml will be deployed as process files. Files ending with ar like .bar or .jar will be deployed as business archives.
cfgfilejbpm.cfg.xmloptionalPoints to the jbpm configuration file that has to be on the classpath in which the jbpm-deploy task was defined.



Table 4.2. jbpm-deploy elements:
ElementMultiplicityDescription
fileset0..*files to be deployed expressed as a plain ant fileset. Files ending with .xml will be deployed as process files. Files ending with ar like .bar or .jar will be deployed as business archives.

4.2. Deploying classes

Since version 4.2 jBPM has a process classloading mechanism as in jBPM 3.
Classes that are referenced from processes must be made available in one of 3 ways:
  • as .class files in your business archive. Unlike in jBPM 3, now the root of the archive file is used as the root for searching class resources. So when class com.superdeluxsandwiches.Order is referenced in the process file, it will be found when it is in the same business archive with entry name com/superdeluxsandwiches/Order.class Classes are cached (key is a combination of deployment and context classloader), so it should perform better then in jBPM 3.
  • as classes available in the web application that calls jBPM. Even when jBPM is deployed server-wide on jboss or tomcat, jBPM will find the classes in your web application or enterprise application that calls jBPM. That's because we use the current context classloader when searching for classes during process execution.
  • as class files that are available server-wide. E.g. like the jars in the lib directories in tomcat and jboss.
In case of the examples, an examples.jar file is created with all the classes and it is put in the lib directory of the JBoss server configuration. Similarly for tomcat. See target install.examples.into.tomcat and install.examples.into.jboss. In one of the future releases we might switch to include the classes in the business archive itself.



For more information follow my Tutorial  online @ http://jbpmmaster.blogspot.com/

No comments:

Post a Comment