Activiti 简易教程

一搭建环境

1.1   JDK 6+

activiti 运行在版本 6以上的 JDK上。转到 Oracle Java SE下载页面,点击按钮“下载 JDK”。网页中也有安装说明。要核实安装是否成功,在命令行上运行 javaversion。将打印出安装的 JDK的版本。

1.2   Ant 1.8.1+

 Ant[http://ant.apache.org/bindownload.cgi]下载页面下载最新稳定版的 Ant。解压文件,确保其 bin文件夹在操作系统的 path 下。在命令行上运行 antversion 来检查 Ant是否安装成功。成功将打印安装的 Ant 版本。

1.3   Eclipse 3.7+

 Eclipse的下载页面下载 Eclipse Classic(Eclipse JEE)版的 eclipse。解压下载的文件,然后就可以运行 eclipse路径下的eclipse 文件了。

下载地址:http://www.eclipse.org/downloads/packages/release/indigo/sr2

1.4   Activiti -eclipse designer插件安装

         在安装Activiti -eclipse designer插件前先安装maven插件,m2e(eclipse)插件在Install New SoftWare安装时会出现些问题,按以下步骤安装即可。

1.4.1 先安装GEF插件

maven插件安装的时候会依赖这个插件,在Eclipse -> help -> Install New SoftWare中安装,update site:http://download.eclipse.org/tools/gef/updates/interim/

1.4.2 安装SVN插件

Eclipse -> help -> Install New SoftWare中安装,update site:http://subclipse.tigris.org/update_1.6.x

1.4.3安装Maven插件

方式一:在线安装

         Eclipse -> help -> Install New SoftWare中安装,update site:http://nexus.tesla.io:8081/nexus/content/sites/m2e.extras/m2e/1.5.0/N/LATEST/

顺便eclipse m2e支持sitehttp://www.eclipse.org/m2e/download/

         如在线安装不成功,报[the selected did not contain any resources that can run on server maven project]错误,建议采用方式二安装。

方式二:本地安装

         下载maven eclipse-maven3-plugin插件(eclipse-maven3-plugin为本人CSDN上传)

Maven site: http://ant.apache.org/bindownload.cgi

eclipse-maven3-plugin site: http://download.csdn.net/detail/yangyi22/5663245

         eclipse目录下建立myplugins目录,将eclipse-maven3-plugin解压后文件复制进去,建立links目录,新建maven.link文件(名字随意取)添加文本:

path=…/eclipse/myplugins/maven,即让eclipse启动时去寻找myplugins中的插件,如本人安装的路径:path=D:/Java~coding~site /eclipse[indigo-jee]/eclipse/myplugins/maven

1.4.4 最后安装Activiti -eclipse designer

打开 HelpàInstall New Software。在如下面板中,点击Add按钮,然后填入下列字段:lNameActiviti BPMN 2.0 designer

Locationhttp://activiti.org/designer/update/

 

安装成功后,新建activiti项目,视图如下:

 

安装m2eclipse插件后,重启Eclipse,如提示

Eclipse is running in a JRE, but a JDK is required

  Some Maven plugins may not work when importing projects or updating source folders.

需要修改eclipse.ini文件,新增一项配置

-vm配置项必须在–vmargs配置项前,是因为执行到-vmargs配置项已经选择了一个默认的JVM了。

所以在–vmargs前面加上这一句:

-vm  

C:/Program Files/Java/jdk1.6.0_20/bin/javaw.exe 

二开始activiti 5.10的第一个demo

2.1   建立activiti-demo工程,选择Activiti Project

 

创建成功后的项目:

 

activiti-demo项目添加activiti依赖包,项目右键Build Path->Configure Build Path->libraries -> Add External Jars选中…\activiti-5.10\setup\files\dependencies\libs下所有包添加即可。

2.2 activiti-demo工程的数据库整合为MySQL

         …\activiti-5.10\setup\build\activiti-cfg目录下的activiti.cfg.xml配置文件复制到项目src\main\resources目录下,修改数据库配置如下:

<!-- Database configurations -->

    <propertyname="jdbcUrl"

value="jdbc:mysql://localhost:3306/test?autoReconnect=true"/>

    <propertyname="jdbcDriver"

       value="com.mysql.jdbc.Driver"/>

    <propertyname="jdbcUsername"value="root"/>

    <propertyname="jdbcPassword"value="root"/>

    <!-- Database configurations -->

    <propertyname="databaseSchemaUpdate"value="true"/>

    <!-- job executor configurations -->

    <propertyname="jobExecutorActivate"value="false"/>

2.3 设计activiti-demo工程的流程

在该项目的src/main/resource/diagrams下右键创建Activiti diagram,文件名为:DemoProcess.bpmn

 -->

 

此时进入Activiti Diagram Editor,在空白处点一下,下边属性栏中设置idnameid就是这个流程的key,后边启动流程的时候使用到。

 

注意:Activiti 5.8升级到5.9以后,xxx.bpmn20.xmlxxx.png已不默认生成,仅仅是生成xxx.bpmn文件,xxx.bpmn中的定义内容就如xxx.bpmn20.xml一样。

        另外,快捷菜单:“Create deployment artifacts”和“Import BPMN20 file”,在5.9以后去掉了。

如需设计完成流程后自动生成一个png图片按如下处理

l  保存无法生存png图片按以下处理

Window –> Preferences -> Activiti ->Save勾选即可

或者手动操作Activiti Designer打开xxx.bpmn文件,然后右键选择Export Diagram...,在弹出的对话框中设置图片的参数即可,一般使用默认就可以了。

在设计编辑器中保存DemoProcess.bpmn后的项目视图如下:

 

测试类代码  DemoProcessTest.java

[java] view plaincopy
  1. package main.java;  
  2.   
  3. import java.io.FileInputStream;  
  4. import java.util.List;  
  5. import org.activiti.engine.HistoryService;  
  6. import org.activiti.engine.ProcessEngine;  
  7. import org.activiti.engine.ProcessEngineConfiguration;  
  8. import org.activiti.engine.RepositoryService;  
  9. import org.activiti.engine.RuntimeService;  
  10. import org.activiti.engine.TaskService;  
  11. import org.activiti.engine.history.HistoricProcessInstance;  
  12. import org.activiti.engine.runtime.ProcessInstance;  
  13. import org.activiti.engine.task.Task;  
  14.   
  15. /** 
  16.  * Activiti 5.10 demo 
  17.  * @author BruceQin 
  18.  *  
  19.  */  
  20. public class DemoProcessTest {  
  21.     // diagrams实际路径  
  22.     private static String realPath =   
  23.             "D:\\Java~coding~site\\J2EE-IDE\\Workspace\\workspace[indigo-jee]" +  
  24.             "\\activiti-demo\\src\\main\\resources\\diagrams";  
  25.     public static void main(String[] args) throws Exception {  
  26.         // 创建 Activiti流程引擎  
  27.         ProcessEngine processEngine = ProcessEngineConfiguration  
  28.                 .createProcessEngineConfigurationFromResource("activiti.cfg.xml")  
  29.                 .buildProcessEngine();  
  30.           
  31.         // 取得 Activiti 服务  
  32.         RepositoryService repositoryService = processEngine.getRepositoryService();  
  33.         RuntimeService runtimeService = processEngine.getRuntimeService();  
  34.   
  35.         // 部署流程定义  
  36.         repositoryService  
  37.                 .createDeployment()  
  38.                 .addInputStream("DemoProcess.bpmn",new FileInputStream(realPath + "\\DemoProcess.bpmn"))  
  39.                 .addInputStream("DemoProcess.png"new FileInputStream(realPath + <a href="file://\\DemoProcess.png">\\DemoProcess.png</a>))  
  40.                 .deploy();  
  41.           
  42.         // 启动流程实例  
  43.         ProcessInstance instance = processEngine  
  44.                  .getRuntimeService().startProcessInstanceByKey("DemoProcess");  
  45.         String procId = instance.getId();  
  46.         System.out.println("procId:"+ procId);  
  47.           
  48.         // 获得第一个任务  
  49.         TaskService taskService = processEngine.getTaskService();  
  50.         List<Task> tasks = taskService.createTaskQuery().taskDefinitionKey("firstTask").list();  
  51.         for (Task task : tasks) {  
  52.             System.out.println("Following task is: taskID -" +task.getId()+" taskName -"+ task.getName());  
  53.             // 认领任务  
  54.             taskService.claim(task.getId(), "testUser");  
  55.         }  
  56.            
  57.         // 查看testUser 现在是否能够获取到该任务  
  58.         tasks = taskService.createTaskQuery().taskAssignee("testUser").list();  
  59.         for (Task task : tasks) {  
  60.             System.out.println("Task for testUser: " + task.getName());  
  61.             // 完成任务  
  62.             taskService.complete(task.getId());  
  63.         }  
  64.         System.out.println("Number of tasks for testUser: "  
  65.                 + taskService.createTaskQuery().taskAssignee("testUser").count());  
  66.           
  67.   
  68.         // 获取并认领第二个任务  
  69.         tasks = taskService.createTaskQuery().taskDefinitionKey("secondTask").list();  
  70.         for (Task task : tasks) {  
  71.             System.out.println("Following task is : taskID -" +task.getId()+" taskName -"+ task.getName());  
  72.             taskService.claim(task.getId(), "testUser");  
  73.         }  
  74.           
  75.         //完成第二个任务结束结束流程  
  76.         for (Task task : tasks) {  
  77.             taskService.complete(task.getId());  
  78.         }  
  79.           
  80.         // 核实流程是否结束  
  81.         HistoryService historyService = processEngine.getHistoryService();  
  82.         HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(procId).singleResult();  
  83.         System.out.println("Process instance end time: " + historicProcessInstance.getEndTime());  
  84.     }  
  85. }  


教程一完毕。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/388046.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

xargs命令详解,xargs与管道的区别

在工作中经常会接触到xargs命令&#xff0c;特别是在别人写的脚本里面也经常会遇到&#xff0c;但是却很容易与管道搞混淆&#xff0c;本篇会详细讲解到底什么是xargs命令&#xff0c;为什么要用xargs命令以及与管道的区别。为什么要用xargs呢&#xff0c;我们知道&#xff0c;…

pytorch回归_PyTorch:用岭回归检查泰坦尼克号下沉

pytorch回归In this notebook, we shall use this dataset containing data about passengers from the Titanic. Based on this data, we will use a Ridge Regression model which just means a Logistic Regression model that uses L2 Regularization for predicting wheth…

Java后台与VUE跨域交接

后台代码&#xff1a;package com.cn.Mr.Zhong.filter;import org.springframework.stereotype.Component;import javax.servlet.*;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;impor…

koa2 中使用 svg-captcha 生成验证码

1. 安装svg-captcha $ npm install --save svg-captcha 2. 使用方法 生成有4个字符的图片和字符串const svgCaptcha require(svg-captcha)const cap svgCaptcha.create({size: 4, // 验证码长度width:160,height:60,fontSize: 50,ignoreChars: 0oO1ilI, // 验证码字符中排除 …

Weblogic 节点启动

1.启动管理理节点export JAVA_OPTIONS"$JAVA_OPTIONS -Dcom.sun.xml.namespace.QName.useCompatibleSerialVersionUID1.0 -Djava.security.egdfile:/dev/./urandom"nohup ./startWebLogic.sh >admin.log &tail -f admin.log2.启动节点ssonohup ./startManaged…

[Swift]LeetCode74. 搜索二维矩阵 | Search a 2D Matrix

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号&#xff1a;山青咏芝&#xff08;shanqingyongzhi&#xff09;➤博客园地址&#xff1a;山青咏芝&#xff08;https://www.cnblogs.com/strengthen/&#xff09;➤GitHub地址&a…

iris数据集 测试集_IRIS数据集的探索性数据分析

iris数据集 测试集Let’s explore one of the simplest datasets, The IRIS Dataset which basically is a data about three species of a Flower type in form of its sepal length, sepal width, petal length, and petal width. The data set consists of 50 samples from …

Oracle 12c 安装 Linuxx86_64

1)下载Oracle Database 12cRelease 1安装介质 官方的下载地址&#xff1a; 1&#xff1a;http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html 2&#xff1a;https://edelivery.oracle.com/EPD/Download/get_form?egroup_aru_number16496…

Linux入门实验

学习Linux要先做实验来熟悉操作系统本次先写点入门的操作。 关于Linux入门实验的操作如下&#xff1a; 【例1】显示当前使用的shell [rootcentos7 ~]# echo ${SHELL} /bin/bash 【例2】显示当前系统使用的所有shell [rootcentos7 ~]#cat /etc/shells /bin/sh /bin/bash /usr/bi…

flink 检查点_Flink检查点和恢复

flink 检查点Apache Flink is a popular real-time data processing framework. It’s gaining more and more popularity thanks to its low-latency processing at extremely high throughput in a fault-tolerant manner.Apache Flink是一种流行的实时数据处理框架。 它以容…

917. 仅仅反转字母

给定一个字符串 S&#xff0c;返回 “反转后的” 字符串&#xff0c;其中不是字母的字符都保留在原地&#xff0c;而所有字母的位置发生反转。 示例 1&#xff1a; 输入&#xff1a;"ab-cd" 输出&#xff1a;"dc-ba"示例 2&#xff1a; 输入&#xff1a;&q…

C# socket nat 映射 网络 代理 转发

using System;using System.Collections.Generic;using System.Net;using System.Net.Sockets;using System.Text;using System.Threading;namespace portmap_net{/// <summary>/// 映射器实例状态/// </summary>sealed internal class state{#region Fields (5)pu…

python初学者_初学者使用Python的完整介绍

python初学者A magical art of teaching a computer to perform a task is called computer programming. Programming is one of the most valuable skills to have in this competitive world of computers. We, as modern humans, are living with lots of gadgets such as …

c# nat udp转发

UdpClient myClient;Thread recvThread;//打开udp端口开始接收private void startRecv(int port){myClient new UdpClient(port);recvThread new Thread(new ThreadStart(receive));recvThread.Start();}//停止接收private void stopRecv(){recvThread.Abort();}private void…

【Code-Snippet】TextView

1. TextView文字过长&#xff0c;显示省略号 【参考】 必须要同时设置XML和JAVA&#xff0c;而且&#xff0c;java中设置文字必须是在最后。 android:ellipsize"start|end|middle" //省略号的位置 android:singleLine"true" android:lines"2"…

Object 的静态方法之 defineProperties 以及数据劫持效果

再提一下什么是静态方法&#xff1a; 静态方法&#xff1a;在类身上的方法&#xff0c;  动态方法:在实例身上的方法 Object.defineProperties(obj, props)obj&#xff1a;被添加属性的对象props&#xff1a;添加或更新的属性对象给对象定义属性&#xff0c;如果存在该属性&a…

Spring实现AOP的4种方式

Spring实现AOP的4种方式 先了解AOP的相关术语: 1.通知(Advice): 通知定义了切面是什么以及何时使用。描述了切面要完成的工作和何时需要执行这个工作。 2.连接点(Joinpoint): 程序能够应用通知的一个“时机”&#xff0c;这些“时机”就是连接点&#xff0c;例如方法被调用时、…

如何使用Plotly在Python中为任何DataFrame绘制地图的卫星视图

Chart-Studio和Mapbox简介 (Introduction to Chart-Studio and Mapbox) Folium and Geemap are arguably the best GIS libraries/tools to plot satellite-view maps or any other kinds out there, but at times they require an additional authorization to use the Google…

Java入门系列-26-JDBC

认识 JDBC JDBC (Java DataBase Connectivity) 是 Java 数据库连接技术的简称&#xff0c;用于连接常用数据库。 Sun 公司提供了 JDBC API &#xff0c;供程序员调用接口和类&#xff0c;集成在 java.sql 和 javax.sql 包中。 Sun 公司还提供了 DriverManager 类用来管理各种不…

3.19PMP试题每日一题

在房屋建造过程中&#xff0c;应该先完成卫生管道工程&#xff0c;才能进行电气工程施工&#xff0c;这是一个&#xff1a;A、强制性依赖关系B、选择性依赖关系C、外部依赖关系D、内部依赖关系 作者&#xff1a;Tracy19890201&#xff08;同微信号&#xff09;转载于:https://…