1. related development tools and software used.
1) Eclipse IDE for Java EE developers (eclipse 4.2)
2) jbpm4.4
3) mysql5.5
2. Configure The GPD plug-in for the design process in eclipse.
1) GPD plug-in Directory: jbpm-4.4 \ install \ SRC \ GPD \ jbpm-gpd-site.zip
2) install plug-ins: Eclipse menu help --> install new softwore... open the install window; click Add... In the install window to open the Add repository window; click archive...in the Add repositorywindow, select jbpm-gpd-site.zip.
3) after the installation is complete, you will be prompted whether to restart eclipse and choose restart.
3. Configure jbpm runtime locations.
1) eclipse menu window --> preferences --> JBoss jbpm --> runtime locations
2) In the runtime locations window, click Add... to open the Add location window. Name: name, for example, jbpm4.4; Location: select the unzip installation directory of jbpm4.4.
4. Implement first jbpm4 using unit tests.
1) create a Java project named firstjbpm4.
2) add all jar files under jbpm-4.4 \ jbpm. jar and jbpm-4.4 \ Lib to the classpath path of the project. (Or configure all jbpm4.4 jar files as a user library and then directly reference them in the Project)
3) add jbpm. cfg. XML, jbpm. hibernate. cfg. xml and logging. properties under the jbpm-4.4 \ examples \ src directory to the src directory of the project.
4) The firstjbpm4 project structure is as follows.
5) modify the jbpm. hibernate. cfg. xml file and configure database information.
<? 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">
6) Create a database named jbpm4 in MySQL.
create database jbpm4 default character set utf8;
7) on the project name, right-click New --> source folder and name it process. Process and SRC are at the same level. process definition files are stored in process.
8) design the leave process definition file. Create a package named leave under process, and right-click New --> jbpm process definition on leave and name it leave.
9) Draw a flowchart and use assignee to allocate corresponding task handling personnel.
The leave. jpdl. xml file is as follows:
<? XML version = "1.0" encoding = "UTF-8"?> <Process name = "leave" xmlns = "http://jbpm.org/4.4/jpdl"> <start name = "start1" G = "303,8, 48, 48 "> <transition name =" to submit an application "to =" submit an application "G ="-67, -20 "/> </start> <End name =" end1 "G =" 303,340, "/> <Task Name =" submit an application "G =" 281,88, 92,52 "assignee =" [employee] Xiao Li "> <transition name =" to department manager approval "to =" department manager approval "G ="-91, -20 "/> </task> <Task Name =" department manager approval "G =" 281,172, 92,52 "assignee =" [department manager] "> <transition name =" to General Manager approval "to =" General Manager approval "G ="-79, -20 "/> </task> <Task Name =" General Manager approval "G =" 281,256, 92,52 "assignee =" [General Manager] ZHANG Zong "> <transition name =" to end1 "to =" end1 "G ="-45, -20 "/> </task> </process>
The entire process is: [employee] Xiao Li applies -- "[department manager] Li Zong approves --" [General Manager] ZHANG Zong approves.
10) unit test code.
Package CN. luxh. jbpm4; import Java. util. list; import Org. jbpm. API. configuration; import Org. jbpm. API. processengine; import Org. jbpm. API. processinstance; import Org. jbpm. API. task. task; import Org. JUnit. test; public class jbpm4test {// create a database table for jbpm4.4 @ test public void testcreateschema () {New Org. hibernate. cfg. configuration (). configure ("jbpm. hibernate. cfg. XML "). buildsessionfactory ();} // process engine, which obtains various service interfaces through the process engine: Private processengine = configuration. getprocessengine (); // deployment process definition @ test public void testdeployprocessdefinition () {processengine. getrepositoryservice (). createdeployment (). addresourcefromclasspath ("Leave/leave. jpdl. XML "). addresourcefromclasspath ("Leave/leave.png "). deploy ();} // start the process instance @ test public void teststartprocessinstance () {processinstance = processengine. getexecutionservice (). startprocessinstancebykey ("leave"); system. out. println ("processinstance ID is:" + processinstance. GETID (); system. out. println ("processinstance key is:" + processinstance. getkey (); system. out. println ("processinstance name is:" + processinstance. getname ();} // find the user to-do task @ test public void testfindtasksbyuserid () {string userid = "[employee] Xiao Li "; // string userid = "[department manager] "; // string userid = "[General Manager] "; List <task> tasks = processengine. gettaskservice (). findpersonaltasks (userid); For (Task task: tasks) {system. out. println ("Current handler:" + task. getassignee () + "current task:" + task. getname () ;}}// process to-do @ test public void testcompletetask () {string userid = "[employee] Xiao Li "; // string userid = "[department manager] "; // string userid = "[General Manager] "; List <task> tasks = processengine. gettaskservice (). findpersonaltasks (userid); For (Task task: tasks) {processengine. gettaskservice (). completetask (task. GETID ());}}}
Jbpm4 Environment Construction