Cant find java Delegate class in camunda bpm

I have one Delegate class inside my bpm project , here is my class exmple

public class AddClass implements JavaDelegate {
	public void execute(DelegateExecution execution) throws Exception {
		
		String var = (String) execution.getVariable("input");
	      var = var.toUpperCase();
	      execution.setVariable("input", var);
	}
	public  String sayHello() {
		return  "hello";
	}
}

and i want to invoke this class inside camunda modeller i have tried implementing Delegate expression and it’s relative value ${AddClass.sayHello()} , i have even tried to implement it as a java class but in both cases i have received class not found exception, what should i change to make my bpm logic work?

Hi @Sally,

if you have a Java class, you have to set the Java Class Property in the properties panel of the modeler. The configuration need the whole package and the class name.

<serviceTask id="myTask" name="My Task" camunda:class="org.camunda.bpm.test.MyJavaDelegateClass">

When the process execution arrives this delegate, it will execute the execute method. This means,
you have to call the sayHello method in your execute method.

Does it helps?

Cheers
kristin

3 Likes

thank you :grinning:

Hi @kristin,

What if I am calling a microservice(a REST end point) instead of class.
How would I make that work?

Hi @Albin_Chandy

you can use https://docs.camunda.org/manual/7.8/user-guide/process-engine/connectors/ to call rest or soap endpoints.

Best regards

I have some external jars which I have added as dependencies into the pom.xml file. I have created a local repository which is the lib folder under the main project. Once I added these dependencies, when I deployed the war file, the processEngine throws the exception ClassNotFound:

The process could not be started. : Cannot instantiate process definition PingTest:3:a6d23111-7def-11ea-bc4c-98e743bed6bc: ENGINE-09008 Exception while instantiating class ‘camunda.ExecutePingSMSDelegateTrial’: ENGINE-09017 Cannot load class ‘camunda.ExecutePingSMSDelegateTrial’: camunda.ExecutePingSMSDelegateTrial

Caused by: java.lang.ClassNotFoundException: camunda.ExecutePingSMSDelegateTrial

My delegate is in package: camunda
image

Java class linked to service task:

pom.xml:

<dependency>
<groupId>ddsm</groupId>
<artifactId>smslib</artifactId>
<version>6.2</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>webf</groupId>
<artifactId>server</artifactId>
<version>2.0</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>webf</groupId>
<artifactId>server-gwt</artifactId>
<version>2.0</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>webf</groupId>
<artifactId>tools</artifactId>
<version>2.0</version>
<scope>compile</scope>
</dependency>
camunda-bpm-nexus Camunda Maven Repository https://app.camunda.com/nexus/content/groups/public
    	<repository>
    <id>in-project</id>
    <name>In Project Repo</name>
    <url>file://${project.basedir}/libs</url>
</repository>

Thanks in advance!

How do you refer to your Delegate? Are you using the fully qualified classpath or a Delegate Expression?
Does your Delegate implement the JavaDelegate interface?

Can you show the relevant part of your model and delegate?

@sdibernardo
/PingTest/src/main/java/camunda/ExecutePingSMSDelegateTrial.java
package camunda;

[imports from external jar]
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;

public class ExecutePingSMSDelegateTrial implements JavaDelegate {

@Override
public void execute(DelegateExecution execution) {
           [code that uses classes imported from external jar]
}

}

So far I can not find a typo and the implementation looks good to me.
You could use the vPAV to check what exactly the error is.

Besides that, have you tried renaming both the class and the implementation to see if it is just a simple typo?

Yes, multiple times.
I noticed one thing, when I remove the dependency from the the pom.xml file, it can find the JavaDelegate class.
When I add the dependency again, it throws “Cannot find the class”.

I have also tried to add the dependency using the systemPath tag, when I do that, it cannot locate the class file in the external jars.