JBPM4.3+SSH环境搭建
你要用jBPM4.3,首先至少你要了解
1.UML2.0的活动图(因为jBPM是Activity Diagram模型)
2.Hibernate(因为jBPM集成了Hibernate作为引擎的持久框架)
当然最重要的是你对工作流的系统结构有初步的了解。
具体指引请参考 用户手册和开发手册,这里只是一些简单补充。
一、jBPM4.3下载
sourceforge下载
http://sourceforge.net/projects/jbpm/
svn仓库里下载
http://anonsvn.jboss.org/repos/jbpm/jbpm4
二、搭建环境(GDP在Eclipse上的安装)
当你无法在Eclipse安装jBPM4.3 GDP插件,把你的Eclipse SDK版本升级到3.42就OK了。
本人用Myeclipse8.5
三、Myeclipse8.5安装jbpm4插件
下载好的jBPM4.3解包,找到jbpm-4.3\install\src\gpd\jbpm-gpd-site.zip
菜单【Help】-【MyEclipse Configuration Center】-选中【Software】点击【add site】-【Add from Archive File】选中jbpm-gpd-site.zip 点击ok
在【Personal Sites】将里面的接口右击 add to profile ,再点击右上角 Apply 7 change。自己重启,新建就能看到jbpm的菜单,毕!
四、jBPM4.3+SSH
1.在jbpm-4.3\install\src\db\create下选择你使用的数据库脚本(总共有18张表)
2.使用jbpm-4.3\install\src\demo下的SQL脚本生成测试用的数据
3.spring2.5+
4.hibernate用jbpm4.3的包,不支持ehcache。
四、主要配置文件
jbpm.hibernate.cfg.xml
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration><session-factory> <mapping resource="jbpm.repository.hbm.xml" /> <mapping resource="jbpm.execution.hbm.xml" /> <mapping resource="jbpm.history.hbm.xml" /> <mapping resource="jbpm.task.hbm.xml" /> <mapping resource="jbpm.identity.hbm.xml" /></session-factory></hibernate-configuration>
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"><bean id="dataSource"/></property><property name="typeDefinitions"><ref bean="jbpmTypes" /></property><property name="hibernateProperties"><props><prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop><prop key="hibernate.show_sql">true</prop><prop key="hibernate.format_sql">true</prop></props></property><property name="configLocations"><list><value>classpath:hbm/jbpm.hibernate.cfg.xml</value> //指定你存放的路径</list></property></bean>//大字符串操作<bean id="jbpmTypes"value="string_max" /><property name="typeClass"value="org.jbpm.db.hibernate.StringMax" /></bean><!-- jbpm配置 --><bean id="springHelper" /><bean id="processEngine" factory-bean="springHelper"factory-method="createProcessEngine" /><!-- 模板配置自己写的,不是必须的 --><bean id="jbpmTemplate" ref="processEngine"></property></bean><!-- 事务管理bean(平台依赖,有jdbc/jta/jdbc等等)--><bean id="transactionManager"ref="sessionFactory"></property></bean><aop:config><aop:advisor pointcut="execution(* com.yyaccp.jbpm.biz.*.*(..))"advice-ref="txAdvice" /></aop:config><tx:advice id="txAdvice" transaction-manager="transactionManager"><tx:attributes><tx:method name="delete*" /><tx:method name="save*" /><tx:method name="update*" /><tx:method name="do*" /><tx:method name="*" propagation="SUPPORTS" read-only="true" /></tx:attributes></tx:advice></beans>
<?xml version="1.0" encoding="UTF-8"?><jbpm-configuration> <import resource="jbpm.default.cfg.xml" /> <import resource="jbpm.tx.spring.cfg.xml" /> <import resource="jbpm.jpdl.cfg.xml" /> <import resource="jbpm.bpmn.cfg.xml" /> <import resource="jbpm.identity.cfg.xml" /> <import resource="jbpm.businesscalendar.cfg.xml" /> <import resource="jbpm.console.cfg.xml" /> <!-- <import resource="jbpm.jobexecutor.cfg.xml" /> --> <process-engine-context> <string name="spring.cfg" value="classpath:/config/applicationContext.xml" /> //指定自己的路径 </process-engine-context></jbpm-configuration>
package com.meibiye.util;import java.util.List;import java.util.Map;import org.jbpm.api.Execution;import org.jbpm.api.ExecutionService;import org.jbpm.api.HistoryService;import org.jbpm.api.ManagementService;import org.jbpm.api.ProcessEngine;import org.jbpm.api.ProcessInstance;import org.jbpm.api.RepositoryService;import org.jbpm.api.TaskService;import org.jbpm.api.task.Task;/** * jbpm模板类(初步实现) * * @author Administrator * */public class JbpmTemplate {/** * 部署流程到数据库 * * @param resourceName * 资源文件名字 比如(org/forever/jbpm/jpdl/process.jpdl.xml) * @return 返回流程定义id(格式:key-version) */public String Deploy(String resourceName) {return repositoryService.createDeployment().addResourceFromClasspath(resourceName).deploy();}/** * 创建一个新的流程实例 * * @param processDefinitionKey * (process.jpdl.xml中process标签的key) * @param processInstanceKey * (用户给的key,比如一个请假单的id) * @return 流程实例 */public ProcessInstance addProcessInstance(String processDefinitionKey,String processInstanceKey) {return executionService.startProcessInstanceByKey(processDefinitionKey,processInstanceKey);}/** * 创建一个新的流程实例 * @param processDefinitionKey(process.jpdl.xml中process标签的key) * @param variables 该流程实例要用到的变量 * @param processInstanceKey(用户给定的业务key) * @return */public ProcessInstance addProcessInstance(String processDefinitionKey,Map<String, ?> variables,String processInstanceKey){return executionService.startProcessInstanceByKey(processDefinitionKey, variables, processInstanceKey);}/** * 提交任务 * @param taskId 任务id */public void completeTask(String taskId){taskService.completeTask(taskId);}/** * 将任务流转到指定名字的流程中去 * @param taskId * @param outcome */public void completeTask(String taskId,String outcome){taskService.completeTask(taskId, outcome);}/** * 根据key获取流程实例(这里我使用的uuid) * * @param key * (对应于数据库表jbpm4_execution中的KEY_字段) * @return 返回查找到得流程实例,没有返回null */public ProcessInstance getProcessInstance(String key) {return executionService.createProcessInstanceQuery().processInstanceKey(key).uniqueResult();}/** * 根据executionId获取指定的变量值 * @param executionId * @param variableName * @return */public Object getVariableByexecutionId(String executionId,String variableName){return executionService.getVariable(executionId, variableName);}/** * 根据任务id获取指定变量值 * @param taskId * @param variableName * @return */public Object getVariableByTaskId(String taskId,String variableName){return taskService.getVariable(taskId, variableName);}/** * 获取指定用户名字的任务 * @param userId * @return */public List<Task> findPersonalTasks(String userId){return taskService.findPersonalTasks(userId);}/** * 根据任务id获取任务 * @param taskId * @return */public Task getTask(String taskId) {return taskService.getTask(taskId);}/** * 根据流程实例id获取 * @param executionId * @return */public Execution findExecutionById(String executionId) {return executionService.findExecutionById(executionId);}/** * 彻底删除文件的部署 * * @param deploymentId流程定义id */public void deleteDeploymentCascade(String deploymentId) {repositoryService.deleteDeploymentCascade(deploymentId);}public JbpmTemplate() {}public JbpmTemplate(ProcessEngine processEngine) {this.processEngine = processEngine;repositoryService = processEngine.getRepositoryService();executionService = processEngine.getExecutionService();taskService = processEngine.getTaskService();historyService = processEngine.getHistoryService();managementService = processEngine.getManagementService();}private ProcessEngine processEngine;private RepositoryService repositoryService = null;private ExecutionService executionService = null;private TaskService taskService = null;private HistoryService historyService = null;private ManagementService managementService = null;public ProcessEngine getProcessEngine() {return processEngine;}public void setProcessEngine(ProcessEngine processEngine) {this.processEngine = processEngine;System.out.println(processEngine);repositoryService = processEngine.getRepositoryService();executionService = processEngine.getExecutionService();taskService = processEngine.getTaskService();historyService = processEngine.getHistoryService();managementService = processEngine.getManagementService();}public RepositoryService getRepositoryService() {return repositoryService;}public void setRepositoryService(RepositoryService repositoryService) {this.repositoryService = repositoryService;}public ExecutionService getExecutionService() {return executionService;}public void setExecutionService(ExecutionService executionService) {this.executionService = executionService;}public TaskService getTaskService() {return taskService;}public void setTaskService(TaskService taskService) {this.taskService = taskService;}public HistoryService getHistoryService() {return historyService;}public void setHistoryService(HistoryService historyService) {this.historyService = historyService;}public ManagementService getManagementService() {return managementService;}public void setManagementService(ManagementService managementService) {this.managementService = managementService;}}