ClassNotFoundException occurred on custom java delegate

Dear Community,
I’m implementing a custom JavaDelegate class with spring boot app.

If I include this custom class in the Camunda spring boot application then works fine.
But I want to exclude this class to the external jar file.

When I move this custom class to external jar file and include this jar to the classpath then following error occurred.

If you have any solution, please let me know.

[ Stacktrace ]
021-06-21 12:57:23.464 ERROR 1 — [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.camunda.bpm.engine.ProcessEngineException: ENGINE-09008 Exception while instantiating class ‘wf.splitter.SplitByCaseData’: ENGINE-09017 Cannot load class ‘wf.splitter.SplitByCaseData’: org/camunda/bpm/engine/delegate/JavaDelegate] with root cause

java.lang.ClassNotFoundException: org.camunda.bpm.engine.delegate.JavaDelegate
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ~[na:na]
at java.base/java.lang.ClassLoader.defineClass1(Native Method) ~[na:na]

Best regards,
Shuichi

1 Like

can you upload the model and the java class you’re trying to call?

1 Like

Dear Niall,
Thank you for your quick response!

I created very simple projects in the GitHub.
FYI: “example-workflow-service/start-camunda.bat” is application start batch.

Please clone or check following repositories:

Additional info:

Model file is deployed “example-workflow-service/src/resouces/ExampleFlow.bpmn”
And my custom JavaDelegate is implemented “example-external-wf-tasks/src/main/java/info/s1products/ExampleTask.java”

Thank you.

Have you configured like above for delegate class in your model?

It should be like info.s1products.ExampleTask

1 Like

Would recommend using @Component annotation over full path.

image

1 Like

Hi aravindhrs,
Yes I’m defined same class name in the model.

Hi camunda_sailor
I don’t use this function, it’s very useful. I will try!

But I think this issue caused by jvm class loader, because if I include this class in the same project file then works fine. So this expression function is not affect for this issue.

Hi malcomvx,
Your advice is correct. This issue occurred by class loader.
I can handle external jar files with pom file modification and java command option!

Detail is next message, please see it.
Thank you!

Dear All,
I can handle custom JavaDelegate in external jar files!

Conclusion, this issue is occurred by spring boot class loader mechanism.

Usually, default spring boot application launcher is using “JarLauncher”. But this launcher can not add external classpath.
So I changed it to “PropertiesLauncher”. This launcher can be handle external classpath.
(This way is little bit tricky because you do not specify PropertiesLauncher directly in the pom.xml.)

Following is example of pom.xml for PropertiesLauncher.

<build>
	<plugins>
		<plugin>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-maven-plugin</artifactId>
			<configuration>
				<mainClass>${start.class}</mainClass>
				<layout>ZIP</layout>
			</configuration>
			<executions>
				<execution>
					<goals>
						<goal>repackage</goal>
					</goals>
				</execution>
			</executions>
		</plugin>
	</plugins>
</build>

And also, I added “-Dloader.path=extlibs/*” on my application command line.
Then custom delegate works perfect :slight_smile:

I committed new pom.xml and batch file in github repositories.
Please check them if same issue occurred.

Thank you again!