1.新建Java项目,
2.在src目录下加入以下文件:基本可以从jbpm4的下载目录的src目录找到。
jbpm.businesscalendar.cfg.xml
jbpm.cfg.png
jbpm.cfg.xml
jbpm.hibernate.cfg.png
jbpm.hibernate.cfg.xml
3.新建流程定义文件:hello.jpdl.xml
其中内容为:
<?xml version="1.0" encoding="UTF-8"?> <process name="hello" xmlns="http://jbpm.org/4.0/jpdl"> <start name="start1" g="247,64,48,48"> <transition name="to state1" to="state1" g="-59,-17" /> </start> <state name="state1" g="254,167,92,52"> <transition name="to end1" to="end1" g="-47,-17" /> </state> <end name="end1" g="244,277,48,48" /> </process>
4.修改jbpm.hibernate.cfg.xml文件。我使用mysql数据库连接:
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <!-- hsqldb <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property> <property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property> <property name="hibernate.connection.url">jdbc:hsqldb:mem:.</property> <property name="hibernate.connection.username">sa</property> <property name="hibernate.connection.password"></property> --> <!-- mysql <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> --> <property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect </property> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost/jbpmdb</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">123456</property> <!-- <property name="hibernate.hbm2ddl.auto">create-drop</property> --> <property name="hibernate.format_sql">true</property> <mapping resource="jbpm.repository.hbm.xml" /> <mapping resource="jbpm.execution.hbm.xml" /> <mapping resource="jbpm.history.hbm.xml" /> <mapping resource="jbpm.task.hbm.xml" /> <mapping resource="jbpm.identity.hbm.xml" /> </session-factory> </hibernate-configuration>
5.新建测试java类:
public class HelloTest extends TestCase {
// 定义一个jbpm4的外观接口,所有的功能服务都是从ProcessEngine里获取的
public static ProcessEngine processEngine = null;
String deployId = null;
// 主要是用来发布流程
public static RepositoryService repositoryService = null;
// 主要用来启动流程,执行流程
ExecutionService executionService = null;
public HelloTest(){
processEngine = Configuration.getProcessEngine();
}
public void testDeploy(){
repositoryService = processEngine.getRepositoryService();
String deployMentId = repositoryService.createDeployment().addResourceFromClasspath("hello.jpdl.xml").deploy();
List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().list() ;
for (ProcessDefinition processDefinition : list) {
System.out.println(processDefinition.getId());
}
}
public static void main(String[] args) {
HelloTest test = new HelloTest();
test.repositoryService = test.processEngine.getRepositoryService();
String deployMentId = repositoryService.createDeployment().addResourceFromClasspath("hello.jpdl.xml").deploy();
List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().list() ;
for (ProcessDefinition processDefinition : list) {
System.out.println(processDefinition.getId());
}
}
}
6.加入jbpm4的依赖包:
在jbpm4的lib目录下所有jar包以及jbpm.jar
如果是使用用户自定义的库路径会报一个什么xml文件不能解析的错误。估计是加载路径的问题。
可以直接配置依赖直接添加jar包到工程中。