Activiti5.10 Easy Tutorial One

Source: Internet
Author: User

Activiti5.10 Easy Tutorial One

A Built Environment

1.1 JDK 6+

The Activiti runs on the JDK above version 6. Go to the Oracle Java SE download page and click the button "Download JDK". Installation instructions are also available on the Web page. To verify that the installation was successful, run java–version on the command line. The version of the installed JDK will be printed out.

1.2 Ant 1.8.1+

Download the latest stable version of Ant from the ant[http://ant.apache.org/bindownload.cgi] download page. Unzip the file and make sure its Bin folder is under the path of the operating system. Run ant–version on the command line

To check if ANT is installed successfully. Successful installation of the ANT version will be printed.

1.3 Eclipse 3.7+

Download Eclipse Classic (or Eclipse JEE) version of Eclipse from the Eclipse download page. Unzip the downloaded file, and then you can run the eclipse file under the eclipse path.

: HTTP://WWW.ECLIPSE.ORG/DOWNLOADS/PACKAGES/RELEASE/INDIGO/SR2

1.4 Activiti-eclipse Designer Plug-in installation

Install the MAVEN plugin before installing the Activiti-eclipse Designer plug-in, and the M2E (Eclipse) plugin will have some problems installing the install New software, and follow the steps below to install it.

1.4.1 Installing the GEF plug-in first

When the Maven plugin is installed, it will be dependent on the plugin, installed in the install New software, help, Eclipse, update site:http://download.eclipse.org/tools/g ef/updates/interim/

1.4.2 Installing the SVN plugin

Installed in the install New software, help, Eclipse, update site:http://subclipse.tigris.org/update_1.6.x

1.4.3 Installing the Maven plugin

Method One: Online installation

Installed in the install New software, help, Eclipse, update site:http://nexus.tesla.io:8081/nexus/content/sites/m2e.extr as/m2e/1.5.0/n/latest/

By the way Eclipse M2E supports site:http://www.eclipse.org/m2e/download/

If the online installation is unsuccessful, quote [the selected did not contain any resources that can run on server MAVEN project] error, it is recommended to use the way two installation.

Mode two: Local installation

Download maven and Eclipse-maven3-plugin plugin (Eclipse-maven3-plugin for myself CSDN upload)

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

Eclipse-maven3-plugin site:http://download.csdn.net/detail/yangyi22/5663245

Set up the Myplugins directory under the Eclipse directory, copy the eclipse-maven3-plugin extracted files, create the links directory, create a new Maven.link file (name random) to add text:

Path=.../eclipse/myplugins/maven, that is, let eclipse start to look for plug-ins in myplugins, such as the path I installed: path=d:/java~coding~site/eclipse[ Indigo-jee]/eclipse/myplugins/maven

1.4.4 Final installation of Activiti-eclipse Designer

Open Helpàinstall New software. In the following panel, click the Add button and fill in the following fields: L Name:activiti BPMN 2.0 Designer

L location:http://activiti.org/designer/update/

After the installation is successful, create a new Activiti project with the following view:

After installing the M2eclipse plugin, restart Eclipse, as prompted:

Eclipse is running in a JRE, but a JDK is required

Some Maven plugins may isn't work when importing projects or updating source folders.

Need to modify the Eclipse.ini file to add a new configuration

The-VM configuration item must be in front of the –vmargs configuration item because a default JVM has been selected for execution to the-vmargs configuration item.

So add this sentence in front of –vmargs:

-vm

C:/Program Files/java/jdk1.6.0_20/bin/javaw.exe

Two start Activiti 5.10 First Demo

2.1 Build Activiti-demo Project, choose Activiti Project

After you create a successful project:

Add Activiti Dependency package to Activiti-demo project, project right-click Build Path->configure Build path->libraries, add External Jars Select ... \acti Viti-5.10\setup\files\dependencies\libs All packages can be added.

2.2 Integrating the Activiti-demo project database into MySQL

Copy the Activiti.cfg.xml configuration file under the \activiti-5.10\setup\build\activiti-cfg directory to the project Src\main\resources directory, and modify the database configuration as follows:

<!--Database Configurations--

< property name = "Jdbcurl"

Value = "Jdbc:mysql://localhost:3306/test?autoreconnect=true"/>

< property name = "Jdbcdriver"

Value = "Com.mysql.jdbc.Driver"/>

< property name = "Jdbcusername" value = "root"/>

< property name = "Jdbcpassword" value = "root"/>

<!--Database Configurations--

< property name = "Databaseschemaupdate" value = "true"/>

<!--Job Executor configurations--

< property name = "Jobexecutoractivate" value = "false"/>

2.3 Design process of Activiti-demo engineering

Under Src/main/resource/diagrams of the project, right-click to create Activiti diagram with the file name: DEMOPROCESS.BPMN.

-

At this point, enter Activiti Diagram Editor, click in the blank, set the ID and name in the property bar below, ID is the key of this process, and then use it when the process is started.

Note: After the Activiti 5.8 upgrade to 5.9, Xxx.bpmn20.xml and xxx.png have not been generated by default, only the XXX.BPMN file is generated, and the definition in XXX.BPMN is like Xxx.bpmn20.xml.

In addition, the shortcut menu: "Create Deployment Artifacts" and "Import BPMN20 file" were removed after 5.9.

To automatically generate a PNG image after the design process is complete as follows

L Save Unable to survive PNG images as per the following processing

Window–> Preferences, Activiti->save Check

or manual operation: Open the XXX.BPMN file with Activiti Designer, then right-click the Export Diagram ..., set the parameters of the picture in the popup dialog box, the general use of the default is OK.

The project view after saving DEMOPROCESS.BPMN in the design editor is as follows:

Test Class Code Demoprocesstest.java

Package Main.java;

Import Java.io.FileInputStream;
Import java.util.List;
Import Org.activiti.engine.HistoryService;
Import Org.activiti.engine.ProcessEngine;
Import org.activiti.engine.ProcessEngineConfiguration;
Import Org.activiti.engine.RepositoryService;
Import Org.activiti.engine.RuntimeService;
Import Org.activiti.engine.TaskService;
Import org.activiti.engine.history.HistoricProcessInstance;
Import org.activiti.engine.runtime.ProcessInstance;
Import Org.activiti.engine.task.Task;

/**
* Activiti 5.10 Demo
* @author Bruceqin
*
*/
public class Demoprocesstest {
Diagrams actual path
private static String Realpath =
"D:\\java~coding~site\\j2ee-ide\\workspace\\workspace[indigo-jee]" +
"\\activiti-demo\\src\\main\\resources\\diagrams";
public static void Main (string[] args) throws Exception {
Creating the Activiti process engine
Processengine Processengine = processengineconfiguration
. Createprocessengineconfigurationfromresource ("Activiti.cfg.xml")
. Buildprocessengine ();

Get Activiti Service
Repositoryservice Repositoryservice = Processengine.getrepositoryservice ();
Runtimeservice Runtimeservice = Processengine.getruntimeservice ();

Deployment process Definition
Repositoryservice
. Createdeployment ()
. Addinputstream ("DEMOPROCESS.BPMN", New FileInputStream (Realpath + "\\DEMOPROCESS.BPMN"))
. Addinputstream ("Demoprocess.png", New FileInputStream (Realpath + "\\DEMOPROCESS.BPMN"))
. deploy ();

To start a process instance
ProcessInstance instance = Processengine
. Getruntimeservice (). Startprocessinstancebykey ("demoprocess");
String procid = Instance.getid ();
System.out.println ("ProcID:" + procid);

Get the first task
Taskservice Taskservice = Processengine.gettaskservice ();
list<task> tasks = Taskservice.createtaskquery (). Taskdefinitionkey ("Firsttask"). List ();
for (Task task:tasks) {
SYSTEM.OUT.PRINTLN ("Following task Is:taskid-" +task.getid () + "taskname-" + task.getname ());
Claiming tasks
Taskservice.claim (Task.getid (), "TestUser");
}

See if TestUser is now able to get to the task
tasks = Taskservice.createtaskquery (). Taskassignee ("TestUser"). List ();
for (Task task:tasks) {
System.out.println ("Task for TestUser:" + task.getname ());
Complete the task
Taskservice.complete (Task.getid ());
}
System.out.println ("Number of the tasks for TestUser:"
+ Taskservice.createtaskquery (). Taskassignee ("TestUser"). Count ());


Get and claim a second task
tasks = Taskservice.createtaskquery (). Taskdefinitionkey ("Secondtask"). List ();
for (Task task:tasks) {
SYSTEM.OUT.PRINTLN ("Following task Is:taskid-" +task.getid () + "taskname-" + task.getname ());
Taskservice.claim (Task.getid (), "TestUser");
}

Complete the second end of the task process
for (Task task:tasks) {
Taskservice.complete (Task.getid ());
}

Verify that the process is complete
Historyservice Historyservice = Processengine.gethistoryservice ();
Historicprocessinstance historicprocessinstance = Historyservice.createhistoricprocessinstancequery (). Processinstanceid (PROCID). Singleresult ();
System.out.println ("Process Instance End time:" + historicprocessinstance.getendtime ());
}
}

Activiti5.10 Easy Tutorial One

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.