I have a series of models defined in XML. We now have a required to create models dynamically without the need for XML files and any restart of the Camunda web app.
I have implemented the dynamic model and deploy as such (modelInstance is a BpmnModelInstance object):
BpmPlatform.getProcessEngineService()
.getProcessEngine("default")
.getRepositoryService()
.createDeployment().addModelInstance("bpmn", modelInstance)
.deploy();
but when the model is deployed and instantiated the following error is thrown:
Caused by: org.camunda.bpm.engine.ProcessEngineException: ENGINE-09008 Exception while instantiating class 'org.camunda.bpm.utility.AssignmentAPINotify': ENGINE-09017 Cannot load class 'org.camunda.bpm.utility.AssignmentAPINotify': org.camunda.bpm.utility.AssignmentAPINotify
at org.camunda.bpm.engine.impl.util.EngineUtilLogger.exceptionWhileInstantiatingClass(EngineUtilLogger.java:78)
at org.camunda.bpm.engine.impl.util.ClassDelegateUtil.instantiateDelegate(ClassDelegateUtil.java:50)
at org.camunda.bpm.engine.impl.task.listener.ClassDelegateTaskListener.getTaskListenerInstance(ClassDelegateTaskListener.java:54)
at org.camunda.bpm.engine.impl.task.listener.ClassDelegateTaskListener.notify(ClassDelegateTaskListener.java:42)
at org.camunda.bpm.engine.impl.task.delegate.TaskListenerInvocation.invoke(TaskListenerInvocation.java:41)
at org.camunda.bpm.engine.impl.delegate.DelegateInvocation.proceed(DelegateInvocation.java:54)
at org.camunda.bpm.engine.impl.delegate.DefaultDelegateInterceptor.handleInvocationInContext(DefaultDelegateInterceptor.java:87)
at org.camunda.bpm.engine.impl.delegate.DefaultDelegateInterceptor.handleInvocation(DefaultDelegateInterceptor.java:59)
at org.camunda.bpm.engine.impl.persistence.entity.TaskEntity.fireEvent(TaskEntity.java:956)
... 119 more
Caused by: org.camunda.bpm.engine.ClassLoadingException: ENGINE-09017 Cannot load class 'org.camunda.bpm.utility.AssignmentAPINotify': org.camunda.bpm.utility.AssignmentAPINotify
at org.camunda.bpm.engine.impl.util.EngineUtilLogger.classLoadingException(EngineUtilLogger.java:135)
at org.camunda.bpm.engine.impl.util.ReflectUtil.loadClass(ReflectUtil.java:107)
at org.camunda.bpm.engine.impl.util.ClassDelegateUtil.instantiateDelegate(ClassDelegateUtil.java:42)
... 126 more
Caused by: java.lang.ClassNotFoundException: org.camunda.bpm.utility.AssignmentAPINotify
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1275)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1104)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.camunda.bpm.engine.impl.util.ReflectUtil.loadClass(ReflectUtil.java:84)
... 127 more
If I save the model as XML and restart there isn't any issue.
I have been seeing if deploymentBuilder.addClasspathResource(""); is the solution but nothing seems to work!
I resolved this by registering the deployment to the process application using the management service
ProcessEngine processEngine = BpmPlatform.getProcessEngineService().getDefaultProcessEngine();
DeploymentBuilder deploymentBuilder = processEngine.getRepositoryService().createDeployment();
deploymentBuilder = deploymentBuilder.addModelInstance(name, modelInstance);
Deployment deployment = deploymentBuilder.deploy();
ManagementService managementService = processEngine.getManagementService();
managementService.registerProcessApplication(deployment.getId(), PROCESS_APPLICATION_REFERENCE);
This was solved with the help of the Camunda forum.