# Creating process definition - flowable java code snippet required

**URL:** <https://forum.flowable.org/t/creating-process-definition-flowable-java-code-snippet-required/95>\
**Category:** Flowable Engine\
**Created:** [November 14, 2016, 1:11pm UTC](https://forum.flowable.org/t/creating-process-definition-flowable-java-code-snippet-required/95 "2016-11-14T13:11:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nihar](https://avatars.discourse-cdn.com/v4/letter/n/da6949/32.png) [@nihar](https://forum.flowable.org/u/nihar)\
**Post date:** [November 14, 2016, 1:11pm UTC](https://forum.flowable.org/t/creating-process-definition-flowable-java-code-snippet-required/95/1 "2016-11-14T13:11:58Z")

</div>

I want to create bpmn process file pragmatically by using flowable source code  
I have put the flowable dependent jar file in our application class path.

our requirement is,in our web application we have to create process definition and deploy the bpmn file using flowable-rest api .

firstly i want to create some tasks and multiple exclusive gateways in the process definition.

Please send me the code snippet to use the existing flowable code to generate xml file for the same

---

<div class="post-metadata">

**Author:** ![tijs](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@tijs](https://forum.flowable.org/u/tijs)\
**Post date:** [November 14, 2016, 1:33pm UTC](https://forum.flowable.org/t/creating-process-definition-flowable-java-code-snippet-required/95/2 "2016-11-14T13:33:30Z")

</div>

Hi,

So you already have the BpmnModel code that creates the tasks?  
Something like this would work for that purpose:

Process process = new Process();  
StartEvent startEvent = new StartEvent();  
startEvent.setId(“start”);  
process.addFlowElement(startEvent);  
UserTask task1 = new UserTask();  
task1.setId(“task1”);  
process.addFlowElement(task1);  
SequenceFlow flow1 = new SequenceFlow();  
flow1.setSourceRef(“start”);  
flow1.setTargetRef("task1);  
process.addFlowElement(flow1);

BpmnModel bpmnModel = new BpmnModel();  
bpmnModel.addProcess(process);

BpmnXMLConverter xmlConverter = new BpmnXMLConverter();  
xmlConverter.convertToXML(bpmnModel);

Best regards,

Tijs

---

<div class="post-metadata">

**Author:** ![nihar](https://avatars.discourse-cdn.com/v4/letter/n/da6949/32.png) [@nihar](https://forum.flowable.org/u/nihar)\
**Post date:** [November 14, 2016, 1:38pm UTC](https://forum.flowable.org/t/creating-process-definition-flowable-java-code-snippet-required/95/3 "2016-11-14T13:38:11Z")

</div>

How can i will add flow condition if its approved/reject

---

<div class="post-metadata">

**Author:** ![joram](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/joram/32/26_2.png) [@joram](https://forum.flowable.org/u/joram)\
**Post date:** [November 15, 2016, 9:36am UTC](https://forum.flowable.org/t/creating-process-definition-flowable-java-code-snippet-required/95/4 "2016-11-15T09:36:24Z")

</div>

You can set a conditionExpression on a Sequenceflow instance. The expression could be something like ${approved}, where approved is a process variable.

---

<div class="post-metadata">

**Author:** ![ornit-shaked](https://avatars.discourse-cdn.com/v4/letter/o/898d66/32.png) [@ornit-shaked](https://forum.flowable.org/u/ornit-shaked)\
**Post date:** [January 22, 2020, 3:06pm UTC](https://forum.flowable.org/t/creating-process-definition-flowable-java-code-snippet-required/95/5 "2020-01-22T15:06:43Z")

</div>

Hi,  
In the above case, will the BPMN model be created with BPMNDiagram, or should I create it manually?  
Thanks.

---

<div class="post-metadata">

**Author:** ![joram](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/joram/32/26_2.png) [@joram](https://forum.flowable.org/u/joram)\
**Post date:** [February 4, 2020, 8:27am UTC](https://forum.flowable.org/t/creating-process-definition-flowable-java-code-snippet-required/95/6 "2020-02-04T08:27:53Z")

</div>

If you create a model using a visual tool like the Flowable Modeler, the BPMNDiagram information will be created automatically. Otherwise, you’d have to do it yourself.
