jBPM5 入门

1. 
jBPM Business Process Management (BPM) 套件: 
     Runtime Engine         引擎 
    Web-based Designer     基于WEB的设计器 Oryx Designer 
    Eclipse Plugin         
    Management Console     管理控制台 
    Miscellaneous          其它如流程仓库Guvnor 

2. 
执行流 
流程描述 - 流程 - 活动 - 事务 

流程实例 
process instance 

3. 
jBPM5 基于BPMN 2.0流程语言 

4. 
安装eclipse jBPM 插件及使用教程 
4.1 
安装需求 
     JDK 1.5+ 
    Ant 1.7+ 
4.2 
下载 jBPM5 安装文件并解压 
http://sourceforge.net/projects/jbpm/files/jBPM%205/jbpm-5.0-Final/  

4.3 
安装Demo 
ant install.demo 

将执行如下任务 
------ 
下载 JBoss AS 
下载 Eclipse 
下载 Drools Guvnor into JBoss AS 
下载 Oryx Designer 
下载 jBPM gwt-console 
下载 jBPM Eclipse plugin 
下载 Drools Eclipse plugin 
4.4 
启动Demo 
ant start.demo 

将执行如下任务 
------ 
启动  H2 database 
启动 JBoss AS 
启动 Eclipse 
启动 Human Task Service 

4.5 
导入例子工程 
http://people.redhat.com/kverlaen/install-eclipse-jbpm.swf  

4.6 
WEB 管理控制台 
http://localhost:8080/jbpm-console  

账号: 
krisv / krisv 

4.7 
流程仓库 
[url]http://localhost:8080/drools-guvnor [/url] 

4.8 
停止Demo 
ant stop.demo 

4.9 官方论坛 
http://community.jboss.org/en/jbpm?view=discussions  


5. 流程对象 

Events 
    Start Event (None, Conditional, Signal, Message, Timer) 
    End Event (None, Terminate, Error, Escalation, Signal, Message, Compensation) 
    Intermediate Catch Event (Signal, Timer, Conditional, Message) 
    Intermediate Throw Event (None, Signal, Escalation, Message, Compensation) 
    Non-interrupting Boundary Event (Escalation, Timer) 
    Interrupting Boundary Event (Escalation, Error, Timer, Compensation) 


Activities 
    Script Task (Java or MVEL expression language) 
    Task 
    Service Task 
    User Task 
    Business Rule Task 
    Manual Task 
    Send Task 
    Receive Task 
    Reusable Sub-Process (Call Activity) 
    Embedded Sub-Process 
    Ad-Hoc Sub-Process 
    Data-Object 

Gateways 
    Diverging 
        Exclusive (Java, MVEL or XPath expression language) 
        Inclusive (Java, MVEL or XPath expression language) 
        Parallel 
        Event-Based 
    Converging 
        Exclusive 
        Parallel 
    Lanes 

Data  
    Java type language 
    Process properties 
    Embedded Sub-Process properties 
    Activity properties 

Connecting objects  
    Sequence flow 


6. 
WS-HT service 
人工任务(非自动化任务) 

生命周期 
1. 
创建 - 准备 - Reserved - 处理 - 完成|失败 
2. 
(准备 - Reserved - 处理) - 挂起 
3. 
(创建 - 准备 - Reserved - 处理) - 错误|退出|忽略 

7. 
流程上下文 
kcontext 
org.drools.runtime.process.ProcessContext 

8. 
Action 

9. 
Node 

10. 
流程变量及作用域 

11. 
约束 
代码约束 
规则约束 

12. 
事件 
流程内部事件 
外部事件 


13. 
定时器 
Timer Event 

14. 
会话:流程实例通过会话与流程引擎交互,会话通过knowledge base的引用查询流程定义.通过会话可以启动流程实例. 

创建knowledge base 
Java代码   收藏代码
  1. KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();  
  2. kbuilder.add(ResourceFactory.newClassPathResource("MyProcess.bpmn"), ResourceType.BPMN2);  
  3. KnowledgeBase kbase = kbuilder.newKnowledgeBase();  


创建Session 

Java代码   收藏代码
  1. StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();  
  2. ProcessInstance processInstance = ksession.startProcess("com.sample.MyProcess");  


添加或移除监听器 

ProcessEventListener 


15. 
整合jBPM 和 MyEclipse8.6 

1. 
下载GEF 
http://www.eclipse.org/downloads/download.php?file=/tools/gef/downloads/drops/3.5.2/R201002241200/GEF-ALL-3.5.2.zip&url=http://download.actuatechina.com/eclipse/tools/gef/downloads/drops/3.5.2/R201002241200/GEF-ALL-3.5.2.zip&mirror_id=385  

2. 
复制步骤4中已经下载的包 
drools 
--------- 
drools-5.2.0.M1-eclipse-all.zip 

jbpm 
--------- 
jbpm-5.0.0-eclipse-all.zip 

3. 解压并安装插件-链接方式 

Drools 
--------- 
E:\bisoft\tools\myeclipse\myplugins\drools520\eclipse 
E:\bisoft\tools\myeclipse\myplugins\drools520\eclipse\features 
E:\bisoft\tools\myeclipse\myplugins\drools520\eclipse\plugins 
E:\bisoft\tools\myeclipse\myplugins\drools520\eclipse\plugins\lib\*.jar 

注意上面的lib目录下的包是安装目录下的lib目录及子目录下的所有JAR包.为了方便,我都放到lib目录下.为什么这样做?因为drools的包依赖这些包,所以必须的. 

jbpm 
------- 
E:\bisoft\tools\myeclipse\myplugins\jbpm5\eclipse\plugins 

gef 
------- 
E:\bisoft\tools\myeclipse\myplugins\gef\eclipse\features 
E:\bisoft\tools\myeclipse\myplugins\gef\eclipse\plugins 

注意这里的GEF不能用前面步骤4的GEF SDK包,因为MyEclipse使用Eclipse3.5,因此要下载3.5对应的GEF SDK包.

链接文件 
------- 
E:\bisoft\tools\myeclipse\dropins\drools520.link 
path=E:\\bisoft\\tools\\myeclipse\\myplugins\\drools520 

E:\bisoft\tools\myeclipse\dropins\gef.link 
path=E:\\bisoft\\tools\\myeclipse\\myplugins\\gef 

E:\bisoft\tools\myeclipse\dropins\jbpm5.link 
path=E:\\bisoft\\tools\\myeclipse\\myplugins\\jbpm5 

4. 配置JBPM运行时 
指向runtime目录 

5. 导入例子 
sample\evaluation 

6. 配置JBOSS_HOME 
指向jboss-5.1.0.GA 

7. 复制build.xml到工程下,并修改 
Xml代码   收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2.   
  3. <project name="jBPM5">  
  4.       
  5.   <property name="install.home" value="E:/bisoft/sharelib/jbpm-installer" />  
  6.   <property name="jboss.home" value="E:/bisoft/jboss-5.1.0.GA" />  
  7.   <property name="jboss.bind.address" value="localhost" />  
  8.   
  9.   <!-- ############ START/STOP ############ -->  
  10.   
  11.   <!-- Start H2 server -->  
  12.   <target name="start.h2">  
  13.     <java classname="org.h2.tools.Server" fork="true" spawn="true">  
  14.       <arg value="-tcp" />  
  15.       <classpath location="${install.home}/db/driver/h2.jar" />  
  16.     </java>  
  17.   </target>  
  18.   <!-- Stop H2 server -->  
  19.   <target name="stop.h2">  
  20.     <java classname="org.h2.tools.Server" fork="true">  
  21.       <classpath location="${install.home}/db/driver/h2.jar" />  
  22.       <arg value="-tcpShutdown" />  
  23.       <arg value="tcp://localhost:9092" />  
  24.     </java>  
  25.   </target>  
  26.   
  27.   <!-- Start JBoss AS -->  
  28.   <target name="start.jboss">  
  29.     <property name="jboss.full.path.win" location="${jboss.home}/bin/run.bat" />  
  30.     <exec executable="${jboss.full.path.win}" spawn="on"  
  31.           os="Windows 7,Windows Vista,Windows XP,Windows 2000,Windows 2003">  
  32.       <env key="JAVA_OPTS" value="-XX:MaxPermSize=256m -Xms256m -Xmx512m" />  
  33.       <arg value="-b" />  
  34.       <arg value="${jboss.bind.address}" />  
  35.       <arg value="-Djbpm.console.directory=${install.home}/sample/evaluation/src/main/resources" />  
  36.     </exec>  
  37.     <waitfor maxwait="5" maxwaitunit="minute" checkevery="30"  
  38.              checkeveryunit="second" timeoutproperty="jboss.timeout">  
  39.       <socket server="${jboss.bind.address}" port="8080" />  
  40.     </waitfor>  
  41.     <fail if="jboss.timeout" message="jboss did not start within 5 minutes"/>  
  42.   </target>  
  43.   <!-- Stop JBoss AS -->  
  44.   <target name="stop.jboss">  
  45.     <exec executable="${jboss.home}/bin/shutdown.bat"  
  46.           os="Windows 7,Windows Vista,Windows XP,Windows 2000,Windows 2003">  
  47.       <arg value="-s" />  
  48.       <arg value="jnp://${jboss.bind.address}:1099" />  
  49.       <arg value="-S" />  
  50.     </exec>  
  51.   </target>  
  52.   
  53.   <!-- Start Human Task Service -->  
  54.   <path id="classpath.human.task">  
  55.     <fileset dir="${install.home}/runtime" includes="**/*.jar"/>  
  56.     <fileset dir="${install.home}/db/driver" includes="**/*.jar"/>  
  57.   </path>  
  58.   <target name="start.human.task">  
  59.     <mkdir dir="${install.home}/task-service/target"/>  
  60.     <javac srcdir="${install.home}/task-service/src" destdir="${install.home}/task-service/target" classpathref="classpath.human.task">  
  61.       <compilerarg value="-Xlint:unchecked"/>  
  62.     </javac>  
  63.     <copy todir="${install.home}/task-service/target">  
  64.       <fileset dir="${install.home}/task-service/resources"/>  
  65.     </copy>  
  66.     <java classname="org.jbpm.DemoTaskService" fork="true">    
  67.       <classpath>  
  68.         <pathelement path="${install.home}/task-service/target"/>  
  69.         <path refid="classpath.human.task" />  
  70.       </classpath>  
  71.     </java>  
  72.   </target>  
  73.   
  74.   <!-- Start Demo -->  
  75.   <target name="start.demo" depends="start.h2,start.jboss,start.human.task" />  
  76.   <!-- Stop Demo -->  
  77.   <target name="stop.demo" depends="stop.h2,stop.jboss" />  
  78.   
  79. </project>  


前面的两个属性根据实际情况修改. 

8. 启动H2数据库, JBOSS, 人工服务 
start.demo 


9. 运行或调试ProcessTest 


10. 如果你的BPMN文件没有对应的编辑器,可以运行这个类并将输出的信息复制到 
myeclipse/configuration/org.eclipse.equinox.simpleconfigurator/bundles.info的最后, 然后删除configuration/org.eclipse.update目录并重启MyEclipse. 

Java代码   收藏代码
  1. package com.sample;  
  2.   
  3. import java.io.File;  
  4. import java.util.ArrayList;  
  5. import java.util.List;  
  6.   
  7. @SuppressWarnings("unchecked")  
  8. public class CreatePluginsConfig {  
  9.     public CreatePluginsConfig() {  
  10.     }  
  11.       
  12.     public static void main(String[] args) {  
  13.         // 插件位置  
  14.         String plugin = "E:\\bisoft\\tools\\myeclipse\\myplugins\\drools520";    
  15.         new CreatePluginsConfig().print(plugin);    
  16.     }  
  17.       
  18.       
  19.     public void print(String path) {  
  20.         List list = getFileList(path);  
  21.         if (list == null) {  
  22.             return;  
  23.         }  
  24.   
  25.         int length = list.size();  
  26.         for (int i = 0; i < length; i++) {  
  27.             String result = "";  
  28.             String thePath = getFormatPath(getString(list.get(i)));  
  29.             File file = new File(thePath);  
  30.             if (file.isDirectory()) {  
  31.                 String fileName = file.getName();  
  32.                 if (fileName.indexOf("_") < 0) {  
  33.                     print(thePath);  
  34.                     continue;  
  35.                 }  
  36.                 String[] filenames = fileName.split("_");  
  37.                 String filename1 = filenames[0];  
  38.                 String filename2 = filenames[1];  
  39.                 result = filename1 + "," + filename2 + ",file:/" + path + "\\"  
  40.                         + fileName + "\\,4,false";  
  41.                 System.out.println(result);  
  42.             } else if (file.isFile()) {  
  43.                 String fileName = file.getName();  
  44.                 if (fileName.indexOf("_") < 0) {  
  45.                     continue;  
  46.                 }  
  47.                 int last = fileName.lastIndexOf("_");// 最后一个下划线的位置  
  48.                 String filename1 = fileName.substring(0, last);  
  49.                 String filename2 = fileName.substring(last + 1, fileName  
  50.                         .length() - 4);  
  51.                 result = filename1 + "," + filename2 + ",file:/" + path + "\\"  
  52.                         + fileName + ",4,false";  
  53.                 System.out.println(result);  
  54.             }  
  55.   
  56.         }  
  57.     }  
  58.   
  59.     public List getFileList(String path) {  
  60.         path = getFormatPath(path);  
  61.         path = path + "/";  
  62.         File filePath = new File(path);  
  63.         if (!filePath.isDirectory()) {  
  64.             return null;  
  65.         }  
  66.         String[] filelist = filePath.list();  
  67.         List filelistFilter = new ArrayList();  
  68.   
  69.         for (int i = 0; i < filelist.length; i++) {  
  70.             String tempfilename = getFormatPath(path + filelist[i]);  
  71.             filelistFilter.add(tempfilename);  
  72.         }  
  73.         return filelistFilter;  
  74.     }  
  75.   
  76.     public String getString(Object object) {  
  77.         if (object == null) {  
  78.             return "";  
  79.         }  
  80.         return String.valueOf(object);  
  81.     }  
  82.   
  83.     public String getFormatPath(String path) {  
  84.         path = path.replaceAll("\\\\", "/");  
  85.         path = path.replaceAll("//""/");  
  86.         return path;  
  87.     }  
  88. }  


11. 
结果 




12. 
stop.demo 

这里有个缺陷, 没有停止人工服务. 因此必须到任务管理器去结束进程. 

13. 
完成. 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值