jbpm版本:4.3
IDE:myeclipse8.5
DB:mysql5.0
1:myeclipse中安装jbpm
a:解压jbpm4.3
b:打开myeclipse8.5---->选择Help菜单---->选择Myeclipse Configuration Center------>打开第三个选项卡SoftWare----->选择右上角add site---->选折add form archive file-----》找到${jbpm_home}\install\src\gpd 目录下找到jbpm-gpd-site.zip即可!name随便输入即可(比如我输入 jpd)!这样下面就看到多一个jpd(部分过程看下图 )
c:一个一个选中jpd下面的文件,点击右击 add to profile即可!
d: 点击右上角apply change按钮即可!
2:生成jbpm数据库表(我这里以安装mysql为列)
a:先打开mysql数据库新建一个数据库比如jbpm(create database jbpm);
b:打开${jbpm_home}\install\src\db\create 下面,找到mysql的表脚本!
c:全部复制过来粘贴到mysql命令行上(当然也可以source ***.sql方式),
3: helloWorld程序
新建一个java project 项目名称为helloJbpm
a:首先导入相应的jar包(导入$(jbpm_home)\lib目录下面的所有jar包和$(jbpm_home}下面的jbpm.jar包到项目中去)
b:导入配置文件(导入${Jbpm_home}\examples\src目录下面的所有配置文件到项目导入src目录下面,然后修改jbpm.hibernate.cfg.xml里面的driver,用户名,密码,数据库名(可以参考${JBPM-home}\install\jdbc目录下面的mysql.properties文件))
c:设计流程文件
选择new-->jbpss jbpm--->jbpm4 process definition文件即可
xml代码:
<?xml version="1.0" encoding="UTF-8"?>
<process name="hello" xmlns="http://jbpm.org/4.0/jpdl">
<start g="112,33,88,48" name="start1">
<transition g="-77,-17" name="to family168" to="family168"/>
</start>
<state g="122,293,92,52" name="family168">
<transition g="-47,-17" name="to end1" to="end1"/>
</state>
<end g="122,400,48,48" name="end1"/>
</process>
d:写一个测试类
package cn.ljz.jbpm;
import java.util.List;
import org.jbpm.api.Configuration;
import org.jbpm.api.Execution;
import org.jbpm.api.ExecutionService;
import org.jbpm.api.ProcessDefinition;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.RepositoryService;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
public class HelloWorldTest {
private static ProcessEngine processEngine;
private static ExecutionService executeServices ;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
processEngine = Configuration.getProcessEngine();//通过单列模式获得流程引擎
executeServices = processEngine.getExecutionService();
}
@Before
public void setUp() throws Exception {
}
@Test
public void testDeployProcess(){
//RepositoryService功能:主要对流程文件进行发布,查看,删除等!
RepositoryService repositoryService = processEngine.getRepositoryService();
//因为helloword.jpdl.xml文件在 classpath目录下就可以直接这样写,如果不在的话应该加上包名
//返回已经发布的流程的id
String processId = repositoryService.createDeployment().addResourceFromClasspath("helloworld.jpdl.xml").deploy();
//查看已经发布流程的列表
List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().list();
System.out.println("已经发布的流程数量为:"+list.size());
for(ProcessDefinition pd:list){
System.out.println("发布流程的名称:"+pd.getName()+",发布流程id"+pd.getId());
}
repositoryService.createProcessDefinitionQuery();
//根据流程id来删除已经发布的流程
//repositoryService.deleteDeployment(processId)
//repositoryService.deleteDeploymentCascade("processId");
//repositoryService.suspendDeployment(processId);这个等价于删除一个流程
//System.out.println("已经发布的流程数量为:"+repositoryService.createProcessDefinitionQuery().list().size());
}
@Test
public void testProcessInstance(){
ProcessInstance processInstance = executeServices.startProcessInstanceByKey("helloworld");
List<ProcessInstance> list = executeServices.createProcessInstanceQuery().list();
for(ProcessInstance pi:list){
System.out.println("流程实例名称:"+pi.getName()+",流程实例key:"+pi.getKey()+",流程实例version:"+pi.getState()+":");
}
//结束流程实例
//executeServices.endProcessInstance(processInstance.getId(), "cancel");
//删除流程实例
//executeServices.deleteProcessInstance(processInstance.getId());
//System.out.println(executeServices.createProcessInstanceQuery().list().size());
System.out.println(processInstance.isActive("state1"));
executeServices.signalExecutionById(processInstance.getId());
}
}
小小解释:执行发布流程文件的时候,可以查看jbpm4_lob,jbpm4_deployment,jbpm4_deployprop,jbpm4_property表多了记录!