`

JBPM4.4(1)-简单工程的搭建

    博客分类:
  • JBPM
阅读更多

源码下载

https://anonsvn.jboss.org/repos/jbpm/jbpm4/

JBPM是什么?

jBPM是一个可扩展、灵活的流程引擎, 它可以运行在独立的服务器上或者嵌入任何Java应用中。

使用的解析语言:JPDL

发布

只需要把jBPM (jbpm-4.X.zip) 下载下来,然后解压到你的硬盘上的什么地方。 你将看到下面的子目录:
•doc: 用户手册,javadoc和开发指南
•examples: 用户手册中用到的示例流程
•install: 用于不同环境的安装脚本
•lib: 第三方库和一些特定的jBPM依赖库
•src: 源代码文件
•jbpm.jar: jBPM主库归档
•migration: 参考开发指南

必须安装的软件

jBPM需要JDK (标准java)5或更高版本。

http://java.sun.com/javase/downloads/index.jsp

为了执行ant脚本,你需要1.7.0或更高版本的apache ant:

http://ant.apache.org/bindownload.cgi



安装数据库

C:\jbpm-4.4\jbpm-4.4\install\src\db\create

数据库的sql文件在这个路径下可以直接导入,也可以通过ant进行更新数据库的配置。

安装插件

网上n多教程了,不截图了,按照网上其它的配置一下吧,挺全的都。

工程创建

打开eclipse新建eclipse工程





完成后将examples中的几个配置文件导进来

修改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>
    
     <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:3306/jbpmdb</property>
     <property name="hibernate.connection.username">jbpm</property>
     <property name="hibernate.connection.password">jbpm</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>



新建流程定义文件如下:





是一个最简单的流程

新建TestHello.java并且继承JbpmTestCase

测试程序如下:

public class TestHello extends JbpmTestCase {
    String deploymentId;

    protected void setUp() throws Exception {
        super.setUp();

        deploymentId = repositoryService.createDeployment()
                .addResourceFromClasspath("com/jbpm/hellojbpm.jpdl.xml")
                .deploy();
    }

    protected void tearDown() throws Exception {
        repositoryService.deleteDeploymentCascade(deploymentId);

        super.tearDown();
    }

    public void testHello() {
        ProcessInstance processInstance = executionService
                .startProcessInstanceByKey("hellojbpm");

        System.out.println("流程实例Id:" + processInstance.getId());
        System.out
                .println("流程定义Id:" + processInstance.getProcessDefinitionId());

        // 判断当前是否位于start节点
        System.out.println("是否位于start节点:" + processInstance.isActive("start"));

        // 判断当前是否位于state节点
        System.out.println("是否位于zhangsan节点:" + processInstance.isActive("zhangsan"));

        System.out.println("------------------------>使流程继续向下执行");

        Execution executionInA = processInstance
                .findActiveExecutionIn("zhangsan");
        assertNotNull(executionInA);

        // 判断当前是否位于state节点

        processInstance = executionService.signalExecutionById(executionInA
                .getId());
        Execution executionInB = processInstance.findActiveExecutionIn("lishi");
        assertNotNull(executionInB);
        
        System.out.println("是否位于lishi节点:" + executionInB.isActive("lishi"));

        processInstance = executionService.signalExecutionById(executionInB
                .getId());
        Execution executionInC = processInstance
                .findActiveExecutionIn("wangwu");
        assertNotNull(executionInC);
        
        System.out.println("是否位于wangwu节点:" + executionInC.isActive("wangwu"));
        
    }

}




运行测试junit文件

结果如下:

流程实例Id:hellojbpm.220007
流程定义Id:hellojbpm-1
是否位于start节点:false
是否位于zhangsan节点:true
------------------------>使流程继续向下执行
是否位于lishi节点:true
是否位于wangwu节点:true

流程一步一步的向下执行了,在这个示例中使用了start和state结点,在后面的示例中,会逐步深入到其它的示例中。

在运行的过程中曾经遇到过一个错误

16:53:39,280 SEV | [AbstractFlushingEventListener] Could not synchronize database state with session

org.hibernate.exception.ConstraintViolationException: could not delete: [org.jbpm.pvm.internal.model.ExecutionImpl#7]

经过查找之后是hibernate的方言指定的有问题,将

org.hibernate.dialect.MySQLDialect

修改成

org.hibernate.dialect.MySQLInnoDBDialect

问题就可以解决了。

 

  • 大小: 64.2 KB
  • 大小: 36.4 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics