cancel
Showing results for 
Search instead for 
Did you mean: 

How to start a process by Standalone in Activiti

sherlock
Champ in-the-making
Champ in-the-making
Hi,
I am new to activiti. I am started exploring from few days.
I am using Activiti 5.9 and eclipse indigo and activiti 5.9.3 designer plugin.

When im trying to create a stand alone program to create a process and run. it's throwing an exception like
SEVERE: Error while closing command context
org.activiti.engine.ActivitiException: no processes deployed with key 'startProcess'.

my MyProcess.bpmn code is like below

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="startProcess" name="Start process">
    <startEvent id="startevent1" name="Start"></startEvent>
    <userTask id="usertask1" name="User Task" activiti:assignee="kermit"></userTask>
    <sequenceFlow id="flow1" name="" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow2" name="" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_startProcess">
    <bpmndi:BPMNPlane bpmnElement="startProcess" id="BPMNPlane_startProcess">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35" width="35" x="120" y="270"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
        <omgdc:Bounds height="55" width="105" x="200" y="260"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35" width="35" x="360" y="270"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="155" y="287"></omgdi:waypoint>
        <omgdi:waypoint x="200" y="287"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="305" y="287"></omgdi:waypoint>
        <omgdi:waypoint x="360" y="287"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>



and my simple java program is like.



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.runtime.ProcessInstance;
import org.activiti.engine.task.Task;



public class Demo {
public static void main(String[] args) {
   
   ProcessEngine processEngine=ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration().buildProcessEngine();
   
   RepositoryService repositoryService=processEngine.getRepositoryService();
   repositoryService.createDeployment().addClasspathResource("diagrams/MyProcess.bpmn").deploy();
   
   RuntimeService runtimeService=processEngine.getRuntimeService();
   ProcessInstance processInstance=runtimeService.startProcessInstanceByKey("startProcess");
   
   TaskService taskService=processEngine.getTaskService();
   Task task=taskService.createTaskQuery().taskAssignee("kermit").singleResult();

   System.out.println(task.getName());
}
}



so please help me what is the wrong in my code.


Thanks
Sherlock
14 REPLIES 14

sunitanayak83
Champ in-the-making
Champ in-the-making

Hi,

I am using Alfresco Activiti and want to initiate a task outside of alfresco activiti. I have written a standalone java program to do this(i.e my java program creates a task in alfresco activiti on execution).

My java program looks like this :

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.runtime.ProcessInstance;
import org.activiti.engine.task.Task;

public class TestingABC {

public static void main(String[] args)
{

//Create Activiti process engine
     ProcessEngine processEngine = ProcessEngineConfiguration
       .createStandaloneInMemProcessEngineConfiguration()
       .buildProcessEngine();

     // Get Activiti services
     RepositoryService repositoryService = processEngine.getRepositoryService();
     RuntimeService runtimeService = processEngine.getRuntimeService();

     // Deploy the process definition
     repositoryService.createDeployment()
       .addClasspathResource("diagram/TestingThruActiviti.bpmn20.xml")
       .deploy();

     // Start a process instance
     ProcessInstance processInstance=runtimeService.startProcessInstanceByKey("TestingThruActiviti");
    
     TaskService taskService=processEngine.getTaskService();
  Task task=taskService.createTaskQuery().taskAssignee("$INITIATOR").singleResult();
 
  System.out.println(task.getName());

    

}

}

The program runs fine as long as my taskAssignee is "$INITIATOR", but when I change my taskAssignee to a real user in alfresco activiti, it throws a null pointer exception.

Exception in thread "main" java.lang.NullPointerException
at TestingABC.main(TestingABC.java:34)

Any pointers ?

jbarrez
Star Contributor
Star Contributor
Well, probably because that task does not exists when you're doing task.getName().
Did you check your database to see what value for the assignee is in that row?

sunitanayak83
Champ in-the-making
Champ in-the-making
I am able to see the name of the task when I assign the task to "$INITIATOR", but I get a null pointer exception when I assign the task to some other assignee(e.g ABC ABC). I am probably not assigning the user properly. What is the proper way of assigning users ? I am using Alfresco Activiti for creating the process and Eclipse IDE for creating the java program(which initiates the task outside of activiti).

sunitanayak83
Champ in-the-making
Champ in-the-making
I am trying to start a process in Alfresco Activiti externally using a standalone java program. My java program and .bpmn20.xml reside on Eclipse IDE. On executing the java program, the process doesn’t get deployed. Any pointers on why this is happening ?

//Create Activiti process engine
     ProcessEngine processEngine = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration().buildProcessEngine();

     //Get Activiti services
     RepositoryService repositoryService = processEngine.getRepositoryService();
     RuntimeService runtimeService = processEngine.getRuntimeService();

     //Deploy the process definition
     repositoryService.createDeployment().addClasspathResource("diagram/TestingThruActiviti.bpmn20.xml").deploy();

     // Start a process instance
     ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("TestingThruActiviti");

     TaskService taskService= processEngine.getTaskService(); 

  Task task=taskService.createTaskQuery().taskAssignee("$INITIATOR").singleResult();

  System.out.println(task.getName());

jbarrez
Star Contributor
Star Contributor
What do you mean 'doesn't get deployed'? Where?

You are booting up an in memory H2 database by doing this "createStandaloneInMemProcessEngineConfiguration". So if you want to see it appear somewhere else, you need the engines to point to the same database.