1.1 JDK 6+
1.2 Ant 1.8.1+
1.3 Eclipse 3.7+
1.4 Activiti -eclipse designer插件安装
1.4.1 先安装GEF插件
1.4.2 安装SVN插件
1.4.3安装Maven插件
1.4.4 最后安装Activiti -eclipse designer
2.1 建立activiti-demo工程,选择Activiti Project
2.2 将activiti-demo工程的数据库整合为MySQL
2.3 设计activiti-demo工程的流程
以上详细描述参照Activiti 简易教程一 version5.10(http://blog.csdn.net/yangyi22/article/details/9225849)
测试类代码 DemoProcessTest.java
package main.java; import java.io.FileInputStream; import java.util.List; import org.activiti.engine.HistoryService; import org.activiti.engine.ProcessEngine; import org.activiti.engine.ProcessEngines; import org.activiti.engine.RepositoryService; import org.activiti.engine.RuntimeService; import org.activiti.engine.TaskService; import org.activiti.engine.history.HistoricProcessInstance; import org.activiti.engine.runtime.ProcessInstance; import org.activiti.engine.task.Task; public class DemoProcessTest { // diagrams实际路径 private static String realPath = "D:\\Java~coding~site\\J2EE-IDE\\Workspace\\workspace[indigo-jee]" + "\\activiti-512demo\\src\\main\\resources\\diagrams"; public static void main(String[] args) throws Exception { // 创建 Activiti流程引擎 //方式一 自动寻找activiti.cfg.xml ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); //方式二 指定加载activiti.cfg.xml // ProcessEngine processEngine = ProcessEngineConfiguration // .createProcessEngineConfigurationFromResource("activiti.cfg.xml") // .buildProcessEngine(); // 取得 Activiti 服务 RepositoryService repositoryService = processEngine.getRepositoryService(); RuntimeService runtimeService = processEngine.getRuntimeService(); // 部署流程定义 repositoryService .createDeployment() .addInputStream("DemoProcess.bpmn",new FileInputStream(realPath + "\\DemoProcess.bpmn")) .addInputStream("DemoProcess.png", new FileInputStream(realPath + "\\DemoProcess.png")) .deploy(); // 启动流程实例 ProcessInstance instance = processEngine .getRuntimeService().startProcessInstanceByKey("DemoProcess"); String procId = instance.getId(); System.out.println("procId:"+ procId); // 获得第一个任务 TaskService taskService = processEngine.getTaskService(); List<Task> tasks = taskService.createTaskQuery().taskDefinitionKey("firstTask").list(); for (Task task : tasks) { System.out.println("Following task is: taskID -" +task.getId()+" taskName -"+ task.getName()); // 认领任务 taskService.claim(task.getId(), "testUser"); } // 查看testUser 现在是否能够获取到该任务 tasks = taskService.createTaskQuery().taskAssignee("testUser").list(); for (Task task : tasks) { System.out.println("Task for testUser: " + task.getName()); // 完成任务 taskService.complete(task.getId()); } System.out.println("Number of tasks for testUser: " + taskService.createTaskQuery().taskAssignee("testUser").count()); // 获取并认领第二个任务 tasks = taskService.createTaskQuery().taskDefinitionKey("secondTask").list(); for (Task task : tasks) { System.out.println("Following task is : taskID -" +task.getId()+" taskName -"+ task.getName()); taskService.claim(task.getId(), "testUser"); } //完成第二个任务结束结束流程 for (Task task : tasks) { taskService.complete(task.getId()); } // 核实流程是否结束 HistoryService historyService = processEngine.getHistoryService(); HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(procId).singleResult(); System.out.println("Process instance end time: " + historicProcessInstance.getEndTime()); } }
依赖jar包说明
Activiti5.10以后的版本已经去掉第三方的jar包,从官网下载的Activiti5.12.1的依赖包仅仅包含activiti相关的jar,目录libs下的jar包如下:
运行测试代码,会发现少了很多依赖包,我的处理的方法是直接从5.10版本导入缺少的jar包,导入后测试代码通过。
jar包:
教程二完毕。
Create By :http://blog.csdn.net/yangyi22/article/details/9254481