Here is an example that shows how to embed jBPM5 in a simple web application.
This example uses the same bpmn file used in the example -http://community.jboss.org/people/bpmn2user/blog/2011/02/21/jbpm5-example-for-forms-with-variables where JBPM5 console is used.
This example uses simple jsp/servlets to access BPM engine.
One should note that any front-end (such as jsp,SpringMVC,Swing,GWT,Flex etc) can be used to access the jBPM engine using the API.
Recommended reading:
1.) http://community.jboss.org/people/bpmn2user/blog/2011/04/03/jbpm5-human-task-api-usage-example
2.) http://community.jboss.org/people/bpmn2user/blog/2011/03/25/jbpm5--persistence-hello-process-example
This example has the following files as shown below.
TaskProcessServlet performs various actions (such as retrieving and completing the tasks etc) using the JBPM API (JbpmAPIUtil.)
HumanTaskStartupServlet starts a sample database (H2) and Mina server for the illustration purpose. It should be noted that Mina server is typically started as a separate process.
How to run and deploy in web container, e.g., Tomcat?
Use maven to create a war file (e.g., mvn package) and copy the war file to TOMCAT_HOME/webapps
A successful deployment shows the following page (e.g., http://localhost:8080/jbpm5webexample/)
A process instance can be created by selecting 'CreateProcess' button.
The tasks for the first user can be retrieved by selectig the button 'Select User'
After completing the task as the first user, krisv, it would wait at the second task, that needs to be approved by 'john'
It is also required to set datasource JNDI.
Refer to http://community.jboss.org/people/bpmn2user/blog/2011/01/21/test for the settings in Tomcat.
Here are the main steps:
1.) Copy the following libraries to TOMCAT_HOME/lib
btm-1.3.1.jar
btm-tomcat55-lifecycle-1.3.3.jar
slf4j-api-1.5.2.jar
slf4j-jdk14-1.5.2.jar
btm-1.3.1.jar
jta-1.1.jar
h2-1.3.155.jar
a.) Create the following btm-config.properties in TOMCAT_HOME/conf
bitronix.tm.serverId=tomcat-btm-node0
bitronix.tm.journal.disk.logPart1Filename=${btm.root}/work/btm1.tlog
bitronix.tm.journal.disk.logPart2Filename=${btm.root}/work/btm2.tlog
bitronix.tm.resource.configuration=${btm.root}/conf/resources.properties
b.) Add transaction and Resource information after 'WatchedResource' line in TOMCAT_HOME/conf/context.xml as shown below.
.........
..........
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Transaction factory="bitronix.tm.BitronixUserTransactionObjectFactory" />
<Resource name="jdbc/testDS1" auth="Container" type="javax.sql.DataSource"
maxActive="15" maxIdle="2" maxWait="10000"
logAbandoned="true"
username="sa" password=""
driverClassName="org.h2.jdbcx.JdbcDataSource"
url="jdbc:h2:tcp://localhost/~/test"/>
..........
.........
c.) Create 'resource.properties' in TOMCAT_HOME/conf as shown below.
resource.ds1.className=bitronix.tm.resource.jdbc.lrc.LrcXADataSource
resource.ds1.uniqueName=jdbc/testDS1
resource.ds1.minPoolSize=0
resource.ds1.maxPoolSize=5
resource.ds1.driverProperties.driverClassName=org.h2.jdbcx.JdbcDataSource
d.) Modify TOMCAT_HOME/conf/server.xml to include BTMLifecycleListener after the line that has GlobalResourcesLifecycleListener as shown below.
.........
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="bitronix.tm.integration.tomcat55.BTMLifecycleListener" />
Also look into the following link to run this example using jBPM5.2
-
jbpm5webexample.zip 20.7 KB
Comments