activiti工程搭建

1.引入activiti的jar包(建议全部引入)在activiti-5.16\libs目录下

   activiti-xxxxxxxx.jar                我们需要的引入的jar     

   activiti-xxxxxxxx-sources.jar  jar包对应的源码不需要引入

如下为activiti的jar包清单,当然还需要引入其他依赖jar包

activiti-bpmn-converter-5.16.4.jar
activiti-bpmn-layout-5.16.4.jar
activiti-bpmn-model-5.16.4.jar
activiti-camel-5.16.4.jar
activiti-cdi.jar
activiti-common-rest-5.16.4.jar
activiti-crystalball-5.16.4.jar
activiti-cxf-5.16.4.jar
activiti-diagram-rest-5.16.4.jar
activiti-engine-5.16.4.jar
activiti-explorer-5.16.4.jar
activiti-image-generator-5.16.4.jar
activiti-json-converter-5.16.4.jar
activiti-ldap-5.16.4.jar
activiti-modeler-5.16.4.jar
activiti-mule-5.16.4.jar
activiti-osgi-5.16.4.jar
activiti-process-validation-5.16.4.jar
activiti-rest-5.16.4.jar
activiti-simple-workflow-5.16.4.jar
activiti-spring-5.16.4.jar

2.在工程中创建activi配置文件,配置数据库连接

     在工程根目录下创建activiti.cfg.xml配置如下:
activiti工程搭建_第1张图片
 

 3.创建一个流程图

 
activiti工程搭建_第2张图片
 4.接下来就可以开发流程


activiti工程搭建_第3张图片
 
 5.创建 Activiti流程启动引擎(下面是通过单例模式实现的)

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.ll.quartz.util.LLSchedulerUtil;

/**
 * 创建 Activiti流程引擎 
 * activiti.cfg.xml配置
 * @author liuli
 *
 */
public class LLProcessEngineConfigurationUtil {
 private static Log log = LogFactory.getLog(LLSchedulerUtil.class);
 private static ProcessEngine processEngine = null;
 private LLProcessEngineConfigurationUtil() {
 }
 static {
  
  try {
   //使用配置文件
       processEngine = ProcessEngineConfiguration
                .createProcessEngineConfigurationFromResource("activiti.cfg.xml")
              .buildProcessEngine();
  } catch (Exception e) {
   log.error(e);
  }
 }

 public static ProcessEngine getProcessEngine() {
  return processEngine;
 }
 public static void destroyProcessEngine(){
    processEngine.close();
 }
}
6.部署流程文件

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.DeploymentBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class LLActivitiDeploy {
 private static Log log = LogFactory.getLog(LLActivitiDeploy.class);
 /**
  *
  * @param resource  要部署的流程文件名称
  * @return
  */
 public static boolean deploy(String resource) {
  String resourceFile = "resource\\activiti\\" + resource + ".bpmn";
  try {
   ProcessEngine processEngine = LLProcessEngineConfigurationUtil.getProcessEngine();
   RepositoryService repositoryService = processEngine.getRepositoryService();
   DeploymentBuilder bulider = repositoryService.createDeployment();
   bulider.addClasspathResource(resourceFile);
   bulider.name(resource);
   bulider.enableDuplicateFiltering();
   bulider.deploy();
   processEngine.close();
  } catch (Exception e) {
   log.error(e.getMessage());
   return false;
  }
  System.out.println("success deploy file:"+resourceFile );
  return true;
 }
 public static void main(String[] args) {
  deploy("zhaoping");
  System.out.println("==voer==");
 }
}

7.查询部署信息


activiti工程搭建_第4张图片
 

你可能感兴趣的:(Activiti)