(Re)Deployment to Tomcat via JavaAPI (with Maven)

Hey there,

I could need some help.

We have a project where we want to deploy an application with an example process to the tomcat server (the one provided by camunda).

The workflow looks like this:
There are changes in the project > We redeploy the project (webapp) via mvn tomcat7:redeploy (this compiles the project to a war file and copies it to the webapps folder from tomcat > the previous version (if there is one) shut be stopped and undeployed to have a new clean deployment > processes from the deployment should be started automatically.

I have read the documentation and tried various ways but after the first successful deployment I get an error message that says:
“Cannot register service org.camunda.bpm.platform.job-executor.process-application:type=DefaultWebRunner with MBeans Container, service with same name already registered”. (DefaultWebRunner was the name I gave to the ProcessApplication Tag, but it also does not work when not adding anything to the Tag)

How can I manage to deploy the same process again in a clean way? Or is it better to add a UUID to the deployment so the engine does not get confused (If so, how can I manage to do that?)?

I hope my problem is understandable, otherwise please ask questions and I’d be happy to clarify our circumstances.

Best regards,
Hendrik

Hi @hoestreich,

are you versioning your definitions?
https://docs.camunda.org/manual/7.5/user-guide/process-engine/process-versioning/

Cheers,
Askar

Hi @aakhmerov,

no at least not explicitly. We just call
processEngine.getRepositoryService().createDeployment() .addClasspathResource(process.getPath()).deploy();

Is this wrong, should it be changed?

Best regards, Hendrik

Finally we solved the problem. Here is a solution in case someone else should have problems with a clean deployment solution.

We have a framework which starts camunda and deploys processes defined in an xml file. The relevant class extends from ServletProcessApplication. The part where the processes are deployed looks like this:

        // deploy available processes
        for (final Process process : config.getProcesses()) {
            LOGGER.trace("Trying to deploy process from path: {}",
                    process.getPath());

            DeploymentBuilder builder = processEngine.getRepositoryService().createDeployment();
            builder.addClasspathResource(process.getPath());
            builder.name(process.getKey());
            builder.source("OurProgram");

            Deployment d = builder.deploy();
            deployedIDs.add(d.getId());

            LOGGER.debug("Deployed process {} from path {} with id {}",
                    process.getKey(), process.getPath(), d.getId());
        }

We save the deployed IDs and do some cleanup in a method annotated with @PreUndeploy:

    public void cleanup(ProcessEngine processEngine) {
        LOGGER.debug("Cleanup before undeployment.");

        for (final String dId : deployedIDs) {
            LOGGER.debug("Trying to undeploy process id {}", dId);
            processEngine.getRepositoryService().deleteDeployment(dId);
        }
    }

Not sure how important this is:

@Override
public void contextDestroyed(final ServletContextEvent sce) {
    super.contextDestroyed(sce);
}

Our processes.xml now looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<process-application
  xmlns="http://www.camunda.org/schema/1.0/ProcessApplication"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <process-archive>
    <process-engine>default</process-engine> 
    <properties>
      <property name="isDeleteUponUndeploy">true</property>
      <property name="isScanForProcessDefinitions">false</property>
    </properties>
  </process-archive>

</process-application>

However this leads to a solution where we can easily undeploy and deploy our application to tomcat with a maven plugin:

<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>

It’s very comfortable this way to test our application framework with a deployment to tomcat / camunda this way.