1. 安装jdk1.6 以上。
2. Eclipse3.6以上
3. eclipse 安装插件: install new software --> add
网络地址:http://activiti.org/designer/update/
安装2次,第一次安装插件依赖包,重启eclipe后,再安装一次,可以安装成功,安装成功后
新建里有activiti的选项如下
另外,在perfence里面
设置
新建项目,maven
配置pom.xml
<properties>
<spring.version>4.3.17.RELEASE</spring.version>
<mysql.version>5.1.39</mysql.version>
<activiti.version>5.22.0</activiti.version>
<mybats.version>3.4.6</mybatis.version>
</properties>
<!-- https://mvnrepository.com/artifact/org.activiti/activiti-engine -->
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-engine</artifactId>
<version>5.22.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.activiti/activiti-spring -->
<!--SSM集成时,要用-->
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring</artifactId>
<version>5.22.0</version>
</dependency>
还需要以下jar的坐标
spring-aspects
spring-aop
spring-context
spring-core
spring-expression
spring-jdbc
spring-tx
spring-beans
需要mybatis
mybatis
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.6</version>
</dependency>
需要slf4j
slf4j-api
slf4j-simple
log4j
####################
另外在pom最后,配置一个build
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
#####################################################
初始化数据库
新建一个数据库activitiDB
创建类去初始化表
新建一个测试类
代码如下
@Test public void createDB() { ProcessEngineConfiguration peconfig = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration(); peconfig.setJdbcUrl("jdbc:mysql://localhost:3306/activitidb"); peconfig.setJdbcDriver("com.mysql.jdbc.Driver"); peconfig.setJdbcUsername("root"); peconfig.setJdbcPassword("123456"); // 配置实例化的方式:drop-create,true peconfig.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE); //得到流程引擎 ProcessEngine buildProcessEngine = peconfig.buildProcessEngine(); }
pom.xml 文件如下
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>cn.taotao</groupId> <artifactId>avtivitiDemo</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>avtivitiDemo</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <!-- https://mvnrepository.com/artifact/junit/junit --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.activiti/activiti-engine --> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-engine</artifactId> <version>5.22.0</version> </dependency> <!-- https://mvnrepository.com/artifact/org.activiti/activiti-spring --> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-spring</artifactId> <version>5.22.0</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-context --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.3.18.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-core --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>4.3.18.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-beans --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>4.3.18.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-aop --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>4.3.18.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>4.3.18.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-tx --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>4.3.18.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-expression --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-expression</artifactId> <version>4.3.18.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-aspects --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> <version>4.3.18.RELEASE</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.4.6</version> </dependency> <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.25</version> </dependency> <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <version>1.7.25</version> <scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.48</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.7.0</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> </project>
//DriverManagerDataSource datasource = new DriverManagerDataSource(); //datasource.setDriverClassName("com.mysql.jdbc.Driver"); //datasource.setUrl("jdbc:mysql://localhost:3306/activitidb"); //datasource.setUsername("root"); //datasource.setPassword("123456"); //peconfig.setDataSource(datasource) ;
上面的也可写成数据源的方式。
另外两种形式
activiti.cfg.xml
位置在/src/main/resource/ 下,需要加入build path的source中
文件如下
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd"> <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration"> <property name="jdbcDriver" value="com.mysql.jdbc.Driver"></property> <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/activitidb"></property> <property name="jdbcUsername" value="root"></property> <property name="jdbcPassword" value="123456"></property> <property name="databaseSchemaUpdate" value="true"></property> </bean> </beans>
代码如下
两种方法写一块了
@Test public void createDb2() { ProcessEngineConfiguration config = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml"); config.buildProcessEngine(); } @Test public void createDB3() { ProcessEngine engine = ProcessEngines.getDefaultProcessEngine(); }
第二种方式,是系统默认去找activiti.cfg.xml 文件,然后直接构建了。