如何以编程方式部署jBPM工作流
您好,很高兴为您解答。
一、Ant文件发布方式
二、Eclipse图形设计器直接部署
三、编程方式部署Jbpm业务程序
编程方式部署Jbpm工作流定义
一、基本知识
1,JUnit测试和执行main方法,实际上是classpath目标目录下的.class文件的运行。查找资源文件,也是从classpath开始的。
2,我们的Web项目应用程序,classpath是web-inf/classes。我们的业务程序定义文件所在目录processes设为src目录。所以,路径应该是“业务程序定义名字/processdefinition.xml”。
这里,我的业务程序定义的名字是checkShowNews,所以classpath的路径应该是checkShowNews/processdefinition.xml。
二、部署业务程序定义的工具类
下面是这个类的源文件,可以通过Main方法和Junit测试部署业务程序定义。
以下是引用片段:
/**
*
*/
package com.withub.common.util;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.graph.def.ProcessDefinition;
import junit.framework.TestCase;
/**
* @author 沈东良 shendl_s@hotmail.com
* 7:21:19 PM
* DeployJbpmProcessDefinition类,提供了部署JBpm工作流定义到数据库的功能!
*/
public class DeployJbpmProcessDefinition extends TestCase {
static JbpmConfiguration jbpmConfiguration = null;
static {
jbpmConfiguration = JbpmConfiguration.getInstance();
}
public void setUp() {
//创建数据库表
//jbpmConfiguration.createSchema();
}
public void tearDown() {
//删除数据库表
//jbpmConfiguration.dropSchema();
}
/**
* 测试方法
*
*/
public void testSimplePersistence() {
// Between the 3 method calls below, all data is passed via the
// database. Here, in this unit test, these 3 methods are executed
// right after each other because we want to test a complete process
// scenario情节. But in reality, these methods represent different
// requests to a server.
// Since we start with a clean, empty in-memory database, we have to
// deploy the process first. In reality, this is done once by the
// process developer.
/**
* 这个方法把业务处理定义通过Hibernate保存到数据库中。
*/
deployProcessDefinition("checkShowNews/processdefinition.xml");
}
/*
<process-definition
xmlns="" name="checkShowNews">
<swimlane name="CheckNewsManagers">
<assignment class="com.withub.wcms.manage.publishNews.jbpmHandler.assignmentHandler.CheckNewsAssignmentHandler" config-type="bean"></assignment>
</swimlane>
<swimlane name="EditNewsUser">
<assignment class="com.withub.wcms.manage.publishNews.jbpmHandler.assignmentHandler.EditNewsAssignmentHandler" config-type="bean"></assignment>
</swimlane>
<start-state name="relatingNewsChannel">
<transition name="" to="checkNews"></transition>
</start-state>
<task-node name="checkNews">
<task name="checkNews" swimlane="CheckNewsManagers"></task>
<transition name="rejected" to="editNews"></transition>
<transition name="passed" to="showNews"></transition>
</task-node>
<end-state name="end"></end-state>
<task-node name="editNews">
<task name="editNews" swimlane="EditNewsUser"></task>
<transition name="commited" to="checkNews"></transition>
</task-node>
<node name="showNews">
<action name="showNewsAction" class="com.withub.wcms.manage.publishNews.jbpmHandler.actionHandler.ShowNews" config-type="bean"/>
<transition name="" to="end"></transition>
</node>
</process-definition>
*/
/**
* "checkShowNews/processdefinition.xml"
*/
public void deployProcessDefinition(String filePath) {
// This test shows a process definition and one execution
// of the process definition. The process definition has
// 3 nodes: an unnamed start-state, a state 's' and an
// end-state named 'end'.
ProcessDefinition processDefinition = ProcessDefinition.parseXmlResource(filePath);
// Lookup the pojo persistence context-builder that is configured above
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
try {
// Deploy the process definition in the database
jbpmContext.deployProcessDefinition(processDefinition);
} finally {
// Tear down the pojo persistence context.
// This includes flush the SQL for inserting the process definition
// to the database.
/*
* 关闭jbpm上下文。删除pojo持久化上下文。
* 这包括刷新SQL来真正的把业务处理定义插入到数据库中。
* */
jbpmContext.close();
}
}
/**
*
* @param args
*/
public static void main(String[] args){
DeployJbpmProcessDefinition instance=new DeployJbpmProcessDefinition();
instance.deployProcessDefinition(args[0]);
}
}
三、Eclipse下使用main测试的方法
1,点击Run选项:
2,选中Main方法测试的
1)项目-----需要classpath,所有的.class文件、jar包和资源文件所在地。
2)main方法所在的类。
3,由于我们的main方法使用了一个参数,所以需要提供一个参数。就是jBPM业务程序定义文件相对于项目的classpath的相对路径。
4,点Run,运行
如若满意,请点击右侧【采纳答案】,如若还有问题,请点击【追问】
希望我的回答对您有所帮助,望采纳!
~ O(∩_∩)O~