activiti6源码启动(activiti源码分析)
本文目录一览:
- 1、activiti6的流程编辑器怎么整合进自己的项目中
- 2、求大神指点!!!java,activiti工作流id和配置文件没问题,但是执行时一直抛异常
- 3、如何把activiti源码导入eclipse
- 4、java activiti 工作流 都需要什么包?
activiti6的流程编辑器怎么整合进自己的项目中
建议你可以看一下咖啡兔的相关技术博文:网页链接,
activiti6和activiti5整合方式一致
1. 为什么要整合
Activiti 5.10版本把原本独立的Activiti Modeler模块整合到了Activiti Explorer中,两者相结合使用起来很方便,通过Modeler设计的流程模型可以直接部署到引擎,也可以把已经部署的流程转换为Model从而在Modeler中编辑。
在实际应用中也有这样的需求,把Modeler整合到业务系统中可以供管理员使用,或者作为BPM平台的一部分存在,很遗憾官方没有给出如何整合Modeler的文档。
2. 整合工作
2.1 下载源码
首先需要从Github下载源码:;可以直接用Git克隆,也可以下载zip格式的压缩包。
2.2 复制文件
复制的所有文件均在activiti-webapp-explorer2目录中。
src/main/resources中的editor.html、stencilset.json、plugins.xml到项目源码的源码根目录,保证编译之后在classes根目录
src/main/webapp中的api、editor、explorer、libs到项目的webapp目录(与WEB-INF目录同级)
2.3 添加依赖
?
123456789101112131415161718192021222324 dependency groupidorg.activiti/groupid artifactidactiviti-explorer/artifactid version5.14/version exclusions exclusion artifactidvaadin/artifactid groupidcom.vaadin/groupid /exclusion exclusion artifactiddcharts-widget/artifactid groupidorg.vaadin.addons/groupid /exclusion exclusion artifactidactiviti-simple-workflow/artifactid groupidorg.activiti/groupid /exclusion /exclusions/dependencydependency groupidorg.activiti/groupid artifactidactiviti-modeler/artifactid version5.14/version/dependency
2.4 添加Java类
添加一个ExplorerRestApplication.java类保存到项目中,注册了一些REST路由。
?
1234567891011121314151617181920212223242526272829 package org.activiti.explorer.rest.application; import org.activiti.editor.rest.application.ModelerServicesInit;import org.activiti.rest.api.DefaultResource;import org.activiti.rest.application.ActivitiRestApplication;import org.activiti.rest.filter.JsonpFilter;import org.restlet.Restlet;import org.restlet.routing.Router; public class ExplorerRestApplication extends ActivitiRestApplication { public ExplorerRestApplication() { super(); } /** * Creates a root Restlet that will receive all incoming calls. */ @Override public synchronized Restlet createInboundRoot() { Router router = new Router(getContext()); router.attachDefault(DefaultResource.class); ModelerServicesInit.attachResources(router); DiagramServicesInit.attachResources(router); JsonpFilter jsonpFilter = new JsonpFilter(getContext()); jsonpFilter.setNext(router); return jsonpFilter; } }
2.5 配置web.xml
在web.xml文件中添加如下配置:
?
12345678910111213141516 !-- Restlet adapter, used to expose modeler functionality through REST --servlet servlet-nameRestletServlet/servlet-name servlet-classorg.restlet.ext.servlet.ServerServlet/servlet-class init-param !-- Application class name -- param-nameorg.restlet.application/param-name param-valueorg.activiti.explorer.rest.application.ExplorerRestApplication/param-value /init-param/servlet !-- Catch all service requests --servlet-mapping servlet-nameRestletServlet/servlet-name url-pattern/service/*/url-pattern/servlet-mapping
2.6 控制器
使用Spring MVC做了一个简单的封装,也可以使用其他的MVC实现。
?
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 package me.kafeitu.demo.activiti.web.workflow; import java.io.ByteArrayInputStream;import java.util.List; import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse; import org.activiti.bpmn.converter.BpmnXMLConverter;import org.activiti.bpmn.model.BpmnModel;import org.activiti.editor.constants.ModelDataJsonConstants;import org.activiti.editor.language.json.converter.BpmnJsonConverter;import org.activiti.engine.RepositoryService;import org.activiti.engine.repository.Deployment;import org.activiti.engine.repository.Model;import org.apache.commons.io.IOUtils;import org.apache.commons.lang3.StringUtils;import org.codehaus.jackson.JsonNode;import org.codehaus.jackson.map.ObjectMapper;import org.codehaus.jackson.node.ObjectNode;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.servlet.ModelAndView;import org.springframework.web.servlet.mvc.support.RedirectAttributes; /** * 流程模型控制器 * * @author henryyan */@Controller@RequestMapping(value = "/workflow/model")public class ModelController { protected Logger logger = LoggerFactory.getLogger(getClass()); @Autowired RepositoryService repositoryService; /** * 模型列表 */ @RequestMapping(value = "list") public ModelAndView modelList() { ModelAndView mav = new ModelAndView("workflow/model-list"); Listmodel list = repositoryService.createModelQuery().list(); mav.addObject("list", list); return mav; } /** * 创建模型 */ @RequestMapping(value = "create") public void create(@RequestParam("name") String name, @RequestParam("key") String key, @RequestParam("description") String description, HttpServletRequest request, HttpServletResponse response) { try { ObjectMapper objectMapper = new ObjectMapper(); ObjectNode editorNode = objectMapper.createObjectNode(); editorNode.put("id", "canvas"); editorNode.put("resourceId", "canvas"); ObjectNode stencilSetNode = objectMapper.createObjectNode(); stencilSetNode.put("namespace", ""); editorNode.put("stencilset", stencilSetNode); Model modelData = repositoryService.newModel(); ObjectNode modelObjectNode = objectMapper.createObjectNode(); modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, name); modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1); description = StringUtils.defaultString(description); modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, description); modelData.setMetaInfo(modelObjectNode.toString()); modelData.setName(name); modelData.setKey(StringUtils.defaultString(key)); repositoryService.saveModel(modelData); repositoryService.addModelEditorSource(modelData.getId(), editorNode.toString().getBytes("utf-8")); response.sendRedirect(request.getContextPath() + "/service/editor?id=" + modelData.getId()); } catch (Exception e) { logger.error("创建模型失败:", e); } } /** * 根据Model部署流程 */ @RequestMapping(value = "deploy/{modelId}") public String deploy(@PathVariable("modelId") String modelId, RedirectAttributes redirectAttributes) { try { Model modelData = repositoryService.getModel(modelId); ObjectNode modelNode = (ObjectNode) new ObjectMapper().readTree(repositoryService.getModelEditorSource(modelData.getId())); byte[] bpmnBytes = null; BpmnModel model = new BpmnJsonConverter().convertToBpmnModel(modelNode); bpmnBytes = new BpmnXMLConverter().convertToXML(model); String processName = modelData.getName() + ".bpmn20.xml"; Deployment deployment = repositoryService.createDeployment().name(modelData.getName()).addString(processName, new String(bpmnBytes)).deploy(); redirectAttributes.addFlashAttribute("message", "部署成功,部署ID=" + deployment.getId()); } catch (Exception e) { logger.error("根据模型部署流程失败:modelId={}", modelId, e); } return "redirect:/workflow/model/list"; } /** * 导出model的xml文件 */ @RequestMapping(value = "export/{modelId}") public void export(@PathVariable("modelId") String modelId, HttpServletResponse response) { try { Model modelData = repositoryService.getModel(modelId); BpmnJsonConverter jsonConverter = new BpmnJsonConverter(); JsonNode editorNode = new ObjectMapper().readTree(repositoryService.getModelEditorSource(modelData.getId())); BpmnModel bpmnModel = jsonConverter.convertToBpmnModel(editorNode); BpmnXMLConverter xmlConverter = new BpmnXMLConverter(); byte[] bpmnBytes = xmlConverter.convertToXML(bpmnModel); ByteArrayInputStream in = new ByteArrayInputStream(bpmnBytes); IOUtils.copy(in, response.getOutputStream()); String filename = bpmnModel.getMainProcess().getId() + ".bpmn20.xml"; response.setHeader("Content-Disposition", "attachment; filename=" + filename); response.flushBuffer(); } catch (Exception e) { logger.error("导出model的xml文件失败:modelId={}", modelId, e); } } }/pre ### 2.7 注意事项 如果使用Spring代理引擎,并且在项目中同时有activiti.cfg.xml文件(不管在main/resources还是test/resources目录),在activiti.cfg.xml里面的引擎中添加下面的配置参数,否则会导致打开Modeler的编辑页面时读取数据返回**204**状态码。 pre class="9e93-95f8-d916-88d9 brush:xml"property name="processEngineName" value="test"/property/pre 引擎默认名称为default,ProcessEngines.getDefaultProcessEngine()查询时会先检索main/resources,然后再检索test/resources的activiti.cfg.xml和activiti-context.xml文件,所以当main/resources监测不到指定文件时就会导致该引擎被当做web应用的引擎对象,这样会导致有两个引擎,所以把引擎的名称改为非默认的“default”。 ## 3. 中文乱码问题解决办法 在JVM参数中添加参数: -Dsun.jnu.encoding=UTF-8 -Dfile.encoding=UTF-8 **参考**:[在Activiti Modeler中设计的流程包含奇数个中文时不能部署问题](;tid=50fromuid=2) ## 4. 效果截图 在最新的kft-activiti-demo版本(1.7.0)中已经集成了Activiti Modeler,可以在线访问,也可以下载源码学习如何配置。 登录[]()后选择**流程管理**-**模型工作区**菜单项即可。 ![kft-activiti-demo中的效果截图](/files/2013/03/kft-activiti-demo-model-workspace.png)![kft-activiti-demo中的效果截图](/files/2013/03/kad-modeler.png)/model
求大神指点!!!java,activiti工作流id和配置文件没问题,但是执行时一直抛异常
包含了所有Activiti的jar包(和源代码jar包)。依赖没有用这种方式发布。 Activiti引擎必须的依赖如下所示(通过mvn dependency:tree生成):
org.activiti:activiti-engine:jar:5.12.1
+- org.apache.commons:commons-email:jar:1.2:compile | +- javax.mail:mail:jar:1.4.1:compile
| \- javax.activation:activation:jar:1.1:compile +- org.apache.commons:commons-lang3:jar:3.1:compile +- org.mybatis:mybatis:jar:3.1.1:compile
+- org.springframework:spring-beans:jar:3.1.2.RELEASE:compile | \- org.springframework:spring-core:jar:3.1.2.RELEASE:compile | +- org.springframework:spring-asm:jar:3.1.2.RELEASE:compile
| \- commons-logging:commons-logging:jar:1.1.1:compile \- joda-time:joda-time:jar:2.1:compile
注意:只有使用了mail service task才必须引入mail依赖jar。
所有依赖可以在Activiti 源码的模块中, 通过mvn dependency:copy-dependencies下载
如何把activiti源码导入eclipse
安装的时候eclipse还是会尝试从网络上去下载,所以需要在Install New SoftWare 对话框中选择 "Avaible Software Suits",在弹出的对话框中选中刚才http路径的那个资源,把他删了,然后再来使用离线方式安装,此时才会真正使用离线安装包。
java activiti 工作流 都需要什么包?
常用的是:activiti-engine-5.91.jar,activiti-spring-5.9.jar;
解释:以上两个只是activiti工作流的常用包,通常会配置如spring开发的java包,还有数据库jar包等进行使用,但具体要用到什么包,这个和业务开发的逻辑有关系,也没办法进行详细说明的,所以只需要先下载常用的两个,其余的辅助包如:日志包、spring包、数据库包、hibernate包、struts包、mybatis包等根据实际需要添加即可。