Start a process from a Java Application

2,110 views
Skip to first unread message

heinzi...@gmail.com

unread,
Jun 8, 2015, 9:30:09 AM6/8/15
to camunda-...@googlegroups.com
Hallo everyone, 

I am a new newbie to Camunda and after doing some tutorials, I am able to start some simple process from the tasklist.
Now, I would like to start my process from a java application (please see attached image).
I want that the user defines two variables and then click the button start process and the process will be executed.
 Moreover, when the user click stop, the process will be killed.

Please I need your help to tell me where I can find the information to do that.

Best Regards, 


Start a process from Java Application.jpg

Sebastian Menski

unread,
Jun 8, 2015, 9:47:49 AM6/8/15
to camunda-...@googlegroups.com, heinzi...@gmail.com
Hi,

you can use the engine RuntimeService to start a process instance by key and also submit variables [1]. It will return the newly created process instance. You can
use it to delete the running instance if you want [2].

Cheers,
Sebastian

heinzi...@gmail.com

unread,
Jun 8, 2015, 1:16:48 PM6/8/15
to camunda-...@googlegroups.com, heinzi...@gmail.com
Hallo Sebastian, 

Thank you for the information.
I understood how to start the process with variables:

*****************
Map<String, Object> variables = new HashMap<String, Object>();
                variables.put("variable1", "value1");
variables.put("variable2", "value2");
processEngine.getRuntimeService().startProcessInstanceByKey("testProcess", variables);
******************

I still have two questions please:

1- In order to delete a process, I use processEngine.getRuntimeService().deleteProcessInstance(processInstanceId,null);   //how to get the processInstanceId? 

2- I already wrote an application in a java project and I have separably my process prepackaged in a .war file and deployed on the server. I want that  through my application (attached in previous comment), to start and stop the process by clicking the button. 
Is the  'Embedded Process Engine' in this case the best? If yes, could you please refer me to some tutorials or give me some detailed explanation of how the code should look like?

Thank you in advance

Sebastian Menski

unread,
Jun 9, 2015, 3:42:33 AM6/9/15
to camunda-...@googlegroups.com, heinzi...@gmail.com
Hi,

1. 

RuntimeService runtimeService = processEngine.getRuntimeService();
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess", variables);
runtimeService
.deleteProcessInstance(processInstance.getId(), null);


2. It depends on what you want to achieve. If you want to use an application server with a shared process engine you can use the REST API to communicate with the
engine from your GUI client. If you don't need a central instance of the engine and multiple clients you can use the embedded process engine to bundle it with your
application. There is no really getting started for an embedded engine but you can have a look at the following parts of the user guide [1,2]. In the spring getting started guide [3]
we use an embedded engine but I don't think you use spring but maybe it gives you some hints.

Cheers,
Sebastian

Sebastian Menski

unread,
Jun 9, 2015, 3:45:04 AM6/9/15
to camunda-...@googlegroups.com, sebastia...@camunda.com, heinzi...@gmail.com
PS: I moved this thread to the camunda BPM user forum
Reply all
Reply to author
Forward
Message has been deleted
0 new messages