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

frederikherema1
Star Contributor
Star Contributor
Are you running from within eclipse? Make sure the "diagram" folder is on your class path (-> make it a source-folder).

sherlock
Champ in-the-making
Champ in-the-making
Are you running from within eclipse? Make sure the "diagram" folder is on your class path (-> make it a source-folder).

Yeah i am running in eclipse and created the diagram folder in the  src/main/resources.

its is pass through the following code its able to find the bpmn process but its not able to find the process id.

RepositoryService repositoryService=processEngine.getRepositoryService();
   repositoryService.createDeployment().addClasspathResource("diagrams/MyProcess.bpmn").deploy();



Please help me….

Thanks
Sherlock

frederikherema1
Star Contributor
Star Contributor
Your process should be a "bpmn20.xml" file, instead of just a "bpmn" file, in order toz be picked up by the BPMNDeployer. If not, it will consider the file as "just another resource"…

You probably copied this from the designer unit-test, which adds the bpmn-file as a stream, naming it "myProcess.bpmn20.xml".

sherlock
Champ in-the-making
Champ in-the-making
Your process should be a "bpmn20.xml" file, instead of just a "bpmn" file, in order toz be picked up by the BPMNDeployer. If not, it will consider the file as "just another resource"…

You probably copied this from the designer unit-test, which adds the bpmn-file as a stream, naming it "myProcess.bpmn20.xml".

when i changed it to bpmn20.xml its giving following exception.

Exception in thread "main" org.activiti.engine.ActivitiException: resource 'diagrams/MyProcess.bpmn20.xml' not found
at org.activiti.engine.impl.repository.DeploymentBuilderImpl.addClasspathResource(DeploymentBuilderImpl.java:59)
at com.sample.Demo.main(Demo.java:41)

and i have tried below code its able to find the process id but while printing the task namecode in the bold font. its giving the follwing Exception




log4j:WARN No appenders could be found for logger (org.apache.ibatis.logging.LogFactory).
log4j:WARN Please initialize the log4j system properly.
Jul 25, 2012 12:38:09 PM org.activiti.engine.impl.ProcessEngineImpl <init>
INFO: ProcessEngine default created
Jul 25, 2012 12:38:09 PM org.activiti.engine.impl.bpmn.deployer.BpmnDeployer deploy
INFO: Processing resource diagrams/MyProcess.bpmn
Jul 25, 2012 12:38:09 PM org.activiti.engine.impl.bpmn.deployer.BpmnDeployer deploy
INFO: Processing resource MyProcess.bpmn20.xml
Jul 25, 2012 12:38:09 PM org.activiti.engine.impl.bpmn.parser.BpmnParse parseDefinitionsAttributes
INFO: XMLSchema currently not supported as typeLanguage
Jul 25, 2012 12:38:09 PM org.activiti.engine.impl.bpmn.parser.BpmnParse parseDefinitionsAttributes
INFO: XPath currently not supported as expressionLanguage
Jul 25, 2012 12:38:09 PM org.activiti.engine.impl.bpmn.deployer.BpmnDeployer deploy
INFO: Processing resource MyProcess.startProcess.png
Exception in thread "main" java.lang.NullPointerException
at com.sample.Demo.main(Demo.java:47)

stand alone code that i deployed is


package com.sample;

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) {
    
    // Create Activiti process engine
    ProcessEngine processEngine = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration().buildProcessEngine();
   
    // Get Activiti services
    RepositoryService repositoryService = processEngine.getRepositoryService();
    RuntimeService runtimeService = processEngine.getRuntimeService();
   
    // Deploy the process definition
    repositoryService.createDeployment().addClasspathResource("diagrams/MyProcess.bpmn").deploy();
     
    // Start a process instance
    runtimeService.startProcessInstanceByKey("startProcess");
    TaskService taskService=processEngine.getTaskService();
   Task task=taskService.createTaskQuery().taskAssignee("kermit").singleResult();
   [b]System.out.println(task.getName());[/b]
  }
}




Thanks
Sherlock

frederikherema1
Star Contributor
Star Contributor
You should also RENAME the file to *.bpmn20.xml

OR

Add the file to the deployment this way:


.addInputStream("myProcess.bpmn20.xml, ReflectUtil.getResourceAsStream("myProcess.bpmn")

As I said, the engine only triggers process-parsing when resource NAME ends with bpmn20.xml

sherlock
Champ in-the-making
Champ in-the-making
You should also RENAME the file to *.bpmn20.xml

OR

Add the file to the deployment this way:


.addInputStream("myProcess.bpmn20.xml, ReflectUtil.getResourceAsStream("myProcess.bpmn")

As I said, the engine only triggers process-parsing when resource NAME ends with bpmn20.xml


Yes fedrick,
I mentioned the file name as you said and i posted the Exception also in the above post as



Exception in thread "main" org.activiti.engine.ActivitiException: resource 'diagrams/MyProcess.bpmn20.xml' not found
at org.activiti.engine.impl.repository.DeploymentBuilderImpl.addClasspathResource(DeploymentBuilderImpl.java:59)
at com.sample.Demo.main(Demo.java:41)

and when i used deployment with addInputStream method.
repositoryService.createDeployment().addInputStream("MyProcess.bpmn20.xml", ReflectUtil.getResourceAsStream("MyProcess.bpmn")).deploy();
its giving follwing error


INFO: ProcessEngine default created
Exception in thread "main" org.activiti.engine.ActivitiException: inputStream for resource 'MyProcess.bpmn20.xml' is null
at org.activiti.engine.impl.repository.DeploymentBuilderImpl.addInputStream(DeploymentBuilderImpl.java:46)
at com.sample.Demo.main(Demo.java:41)


and i mentioned the code that is working  but the following error is occurring while printing the task.getName().


public static void main(String[] args) {
    
    // Create Activiti process engine
    ProcessEngine processEngine = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration().buildProcessEngine();
   
    // Get Activiti services
    RepositoryService repositoryService = processEngine.getRepositoryService();
    RuntimeService runtimeService = processEngine.getRuntimeService();
   
    // Deploy the process definition
    repositoryService.createDeployment().addClasspathResource("diagrams/MyProcess.bpmn").deploy();
     
    // Start a process instance
    runtimeService.startProcessInstanceByKey("startProcess");
    TaskService taskService=processEngine.getTaskService();
   Task task=taskService.createTaskQuery().taskAssignee("kermit").singleResult();
   System.out.println(task.getName());
  }

please help me to get it resolved.

Thanks
Sherlock

frederikherema1
Star Contributor
Star Contributor
Try using

repositoryService.createDeployment().addInputStream("MyProcess.bpmn20.xml", ReflectUtil.getResourceAsStream("diagrams/MyProcess.bpmn")).deploy();

sherlock
Champ in-the-making
Champ in-the-making
Try using

repositoryService.createDeployment().addInputStream("MyProcess.bpmn20.xml", ReflectUtil.getResourceAsStream("diagrams/MyProcess.bpmn")).deploy();


Yeah it worked..

Thank u….
Sherlock

martin_grofcik
Confirmed Champ
Confirmed Champ
It is hard to guess.
Could you create jUnit test?
http://forums.activiti.org/content/sticky-how-write-unit-test