activiti入门开发及部署

作者 : 开心源码 本文共6306个字,预计阅读时间需要16分钟 发布时间: 2022-05-11 共63人阅读

一、开发环境调试

1.安装sdkman使用于管理java环境

curl -s “https://get.sdkman.io” | bash

source “$HOME/.sdkman/bin/sdkman-init.sh”

sdk version

2.安装jdk环境

sdk install java 8u161-oracle

java -version

echo $JAVA_HOME

3.下载tomcat

wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.0.50/bin/apache-tomcat-8.0.50.zip

tar -zxvf apache-tomcat-8.0.50.zip

./apache-tomcat-8.0.50/bin/startup.sh

4.部署activiti

wget https://github.com/Activiti/Activiti/releases/download/activiti-6.0.0/activiti-6.0.0.zip

tar -zxvf activiti-6.0.0.zip

cp activiti-6.0.0/wars/activiti-admin.war apache-tomcat-8.0.50/webapps

cd apache-tomcat-8.0.50/bin

./startup.sh

5.这样就启动tomcat并且部署了activiti

查看网址:http://localhost:8080/activiti-app

账号admin 密码test

二、Activiti6.0快速体验

1.流程参加者

2.流程设计

3.http://localhost:8080/activiti-app打开网址登陆进去

点击identity manager创立使用户

4.kickstart APP创立一个流程

点击Create Process。输入流程信息

5.创立流程并且绑定使用户。保存并关闭编辑器。

6.创立一个app,并且管理流程

点击Apps后,新添加板块。

保存并且发布

7.进入管理员界面

http://localhost:8080/activiti-admin/#/login admin admin

点击Configuration

点击edit Activiti Rest endpoint

三、源码下载

进入github activiti主页,点击fork,到自己的github中。

git clone git@github.com:自己的账号/Activiti.git

cd activiti

git checkout -b activit-study activiti-6.0.0

mvn clean test-compile

四、入门小demo

  1. import java.text.ParseException;
  2. import java.text.SimpleDateFormat;
  3. import java.util.Date;
  4. import java.util.List;
  5. import java.util.Map;
  6. import java.util.Scanner;
  7. import org.activiti.engine.FormService;
  8. import org.activiti.engine.ProcessEngine;
  9. import org.activiti.engine.ProcessEngineConfiguration;
  10. import org.activiti.engine.RepositoryService;
  11. import org.activiti.engine.RuntimeService;
  12. import org.activiti.engine.TaskService;
  13. import org.activiti.engine.form.FormProperty;
  14. import org.activiti.engine.form.TaskFormData;
  15. import org.activiti.engine.impl.form.DateFormType;
  16. import org.activiti.engine.impl.form.StringFormType;
  17. import org.activiti.engine.repository.Deployment;
  18. import org.activiti.engine.repository.DeploymentBuilder;
  19. import org.activiti.engine.repository.ProcessDefinition;
  20. import org.activiti.engine.runtime.ProcessInstance;
  21. import org.activiti.engine.task.Task;
  22. import org.springframework.boot.autoconfigure.SpringBootApplication;
  23. import com.google.common.collect.Maps;
  24. import lombok.extern.slf4j.Slf4j;
  25. @Slf4j
  26. @SpringBootApplication
  27. public class DemoMain {
  28. public static void main(String[] args) {
  29. //创立引擎
  30. ProcessEngine processEngine = getProcessEngine();
  31. //部署流程
  32. ProcessDefinition processDefinition = getProcessDefinition(processEngine);
  33. //启动运行流程
  34. ProcessInstance processInstance = startProcess(processEngine, processDefinition);
  35. //解决流程任务
  36. doTask(processInstance, processEngine);
  37. }
  38. private static void doTask(ProcessInstance processInstance, ProcessEngine processEngine) {
  39. Scanner scanner = new Scanner(System.in);
  40. while(processInstance != null && !processInstance.isEnded()) {
  41. TaskService taskService = processEngine.getTaskService();
  42. List list = taskService.createTaskQuery().list();
  43. for (Task task : list) {
  44. log.info(“待解决任务:{}”, task.getName());
  45. FormService formService = processEngine.getFormService();
  46. TaskFormData taskFormData = formService.getTaskFormData(task.getId());
  47. List formProperties = taskFormData.getFormProperties();
  48. Map variables = Maps.newHashMap();
  49. for (FormProperty formProperty : formProperties) {
  50. String line = null;
  51. if(StringFormType.class.isInstance(formProperty.getType())) {
  52. log.info(“请输入 {} ?”, formProperty.getName());
  53. line = scanner.nextLine();
  54. variables.put(formProperty.getId(), line);
  55. } else if(DateFormType.class.isInstance(formProperty.getType())) {
  56. log.info(“请输入 {} ? 格式(yyyy-MM-dd)”, formProperty.getName());
  57. line = scanner.nextLine();
  58. SimpleDateFormat dateFormat = new SimpleDateFormat(“yyyy-MM-dd”);
  59. try {
  60. Date date = dateFormat.parse(line);
  61. variables.put(formProperty.getId(), date);
  62. } catch (ParseException e) {
  63. e.printStackTrace();
  64. }
  65. } else {
  66. log.info(“类型不支持”);
  67. }
  68. log.info(“您输入的内容是[{}]”,line);
  69. }
  70. taskService.complete(task.getId(), variables);
  71. processInstance = processEngine.getRuntimeService()
  72. .createProcessInstanceQuery()
  73. .processInstanceId(processInstance.getId())
  74. .singleResult();
  75. }
  76. log.info(“待解决任务数量:{}”, list.size());
  77. scanner.close();
  78. }
  79. }
  80. private static ProcessInstance startProcess(ProcessEngine processEngine, ProcessDefinition processDefinition) {
  81. RuntimeService runtimeService = processEngine.getRuntimeService();
  82. ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());
  83. log.info(“启动流程 {}”, processInstance.getProcessDefinitionKey());
  84. return processInstance;
  85. }
  86. private static ProcessDefinition getProcessDefinition(ProcessEngine processEngine) {
  87. RepositoryService repositoryService = processEngine.getRepositoryService();
  88. DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
  89. deploymentBuilder.addClasspathResource(“second_approve.bpmn”);
  90. Deployment deployment = deploymentBuilder.deploy();
  91. String deploymentId = deployment.getId();
  92. ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
  93. .deploymentId(deploymentId)
  94. .singleResult();
  95. log.info(“流程定义文件 {}, 流程ID {}”, processDefinition.getName(), processDefinition.getId());
  96. return processDefinition;
  97. }
  98. private static ProcessEngine getProcessEngine() {
  99. ProcessEngineConfiguration cfg = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration();
  100. ProcessEngine processEngine = cfg.buildProcessEngine();
  101. String name = processEngine.getName();
  102. String version = processEngine.VERSION;
  103. log.info(“流程引擎名称:{},版本:{}”, name, version);
  104. return processEngine;
  105. }
  106. }

五、打包

mvn package

cd target

java jar xx.jar

一、开发环境调试

1.安装sdkman使用于管理java环境

curl -s “https://get.sdkman.io” | bash

source “$HOME/.sdkman/bin/sdkman-init.sh”

sdk version

2.安装jdk环境

sdk install java 8u161-oracle

java -version

echo $JAVA_HOME

3.下载tomcat

wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.0.50/bin/apache-tomcat-8.0.50.zip

tar -zxvf apache-tomcat-8.0.50.zip

./apache-tomcat-8.0.50/bin/startup.sh

4.部署activiti

wget https://github.com/Activiti/Activiti/releases/download/activiti-6.0.0/activiti-6.0.0.zip

tar -zxvf activiti-6.0.0.zip

cp activiti-6.0.0/wars/activiti-admin.war apache-tomcat-8.0.50/webapps

cd apache-tomcat-8.0.50/bin

./startup.sh

5.这样就启动tomcat并且部署了activiti

查看网址:http://localhost:8080/activiti-app

账号admin 密码test

二、Activiti6.0快速体验

1.流程参加者

2.流程设计

3.http://localhost:8080/activiti-app打开网址登陆进去

点击identity manager创立使用户

4.kickstart APP创立一个流程

点击Create Process。输入流程信息

5.创立流程并且绑定使用户。保存并关闭编辑器。

6.创立一个app,并且管理流程

点击Apps后,新添加板块。

保存并且发布

7.进入管理员界面

http://localhost:8080/activiti-admin/#/login admin admin

点击Configuration

点击edit Activiti Rest endpoint

三、源码下载

进入github activiti主页,点击fork,到自己的github中。

git clone git@github.com:自己的账号/Activiti.git

cd activiti

git checkout -b activit-study activiti-6.0.0

mvn clean test-compile

四、入门小demo

五、打包

mvn package

cd target

java jar xx.jar

activiti入门开发及部署

说明
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是摆设,本站源码仅提供给会员学习使用!
7. 如遇到加密压缩包,请使用360解压,如遇到无法解压的请联系管理员
开心源码网 » activiti入门开发及部署

发表回复