Build a Development Environment
1. Install the GPD plug-in for eclipse
After the installation is complete, check window? Whether JBoss jbpm exists in preference
Path jbpm-4.4/install/src/GPD/jbpm-gpd-site.zip
Restart eclipse after installation
2. Add the jar package: jbpm. jar and jar under jbpm_home/lib.
Note that the following JAR packages are not added: servlet-api.jar, JUnit. jar.
Do not add JUnit. jar, because version 3.8.2 conflicts with junit4.
In Tomcat if a javax/El/expressionfactory exception occurs when accessing JSP, You need to copy the three packages juel. jar, juel-engine.jar, juel-impl.jar to Tomcat lib and delete the original el-api.jar. Delete the Three jar files in the project.
The jbpm development kit contains the MySQL driver jar package.
3. The configuration file can be copied from jbpm_home/examples/src /.:
Jbpm. cfg. XML (jbpm configuration file)
Logging. properties (Log File)
Jbpm. hibernate. cfg. XML (hibernate configuration file of jbpm)
Notes
Modify the database connection information in jbpm. hibernate. cfg. xml. If MySQL is used, the dialect must be org. hibernate. dialect. mysql5innodbdialect.
Configure hibernate. hbm2ddl. Auto of jbpm. hibernate. cfg. XML as update. When the process engine is initialized, jbpm automatically creates a table.
The database connection code must be a UTF-8. Otherwise, an exception may be thrown when a process definition containing Chinese characters is deployed, indicating that the SQL syntax is incorrect.
Modify the log output level in logging. properties to warning: Java. util. Logging. lelehandler. Level = warning
4. write the code;
Jbpm Initialization
Initialize the jbpm database environment
New configuration (). Configure ("jbpm. hibernate. cfg. xml"). buildsessionfactory ();
Note that configuration is in the hibernate package.
Get workflow engine
Processengine = new org. jbpm. API. configuration (). buildprocessengine ();
Deployment process
Processengine. getrepositoryservice ()
. Createdeployment ()
. Addresourcefromclasspath ("test. jpdl. xml ")
. Addresourcefromclasspath ("test.png ")
. Deploy ();
Jbpm programming operations:
Start Process (process instance)
Processengine
. Getexecutionservice ().
. Startprocessinstancebykey ("test"); // key to get the process name
End Process
Processengine. getexecutionservice ().
Endprocessinstance ("test.130001", processinstance. state_ended );
Set the process variables. The process variables can be obtained in subsequent processes. Note that the set process variables must implement the serializable interface.
Map map = new hashmap ();
Map. Put ("CID", "James ");
Processengine
. Getexecutionservice ().
. Startprocessinstancebykey ("test", MAP );
Task Processing
Task query:
Task task = processengine. gettaskservice ()
. Createtaskquery ()
. Assignee ("Zhang San"). uniqueresult ();
Task Processing
Processengine. gettaskservice ()
. Completetask (task. GETID ());
Control Flow
Processengine. gettaskservice ()
. Completetask (task. GETID (), outcome );
Set the task to-do list
In the process definition, use assignee to directly specify. For example: # {studentname}
Use Process Variables in process definition assignee.
Group task: Configure assignment-handler in the process definition XML file, and specify the class through assignmenthandlerSet assignee to none.
Query Group tasks and Group tasks with the specified name:
Engine. gettaskservice (). createtaskquery (). Candidate (employeeid). uniqueresult ();
Engine. gettaskservice (). createtaskquery ().
Candidate (employeeid). activityname (taskname). List ();
Note:
1. The flowchart file name is XXX. jpdl. xml. Note that the flowchart file name should not be in Chinese.
Draw a flowchart and set the task to-do list
2. Add an XML validation schema file,
File Location: jbpm-4.4 \ SRC \ jpdl-4.4.xsd
In window? Search for XML catalog in preference, and click Add to add
If no prompt is displayed, you can place spaces or characters in XML to make changes. After the XML changes and is saved, a prompt is displayed based on the DTD.
3. After modifying the XXX. jpdl. xml file, you need to redeploy (call the delopy () method); otherwise, the change will not take effect.