JavaDelegate error: couldn't instantiate class

Hi,

I defined a JavaDelegate class following the steps detailed following documentation sections:
Writing a JavaDelegate and How to solve the error. However, the error reamins. What I did was:

  • Add a service task and set the class field to “org.flowable.CallTask”.

  • Extract my JavaDelegate class: right click on the class > Export > JAR file > (I selected the options “Export generated class files and resources” and “Export Java source files and resources”).

    package org.flowable;

    import org.flowable.engine.delegate.DelegateExecution;
    import org.flowable.engine.delegate.JavaDelegate;
    
    public class CallTask implements JavaDelegate {
    
    	public void execute(DelegateExecution execution) {
               ...
            }
    }
    
  • Copy ithe JAR file to TOMCAT_HOME\wtpwebapps\flowable-app-rest\WEB-INF\lib .

  • Finally, I start the process from flowable-task application.

The error appears when the flow arribes to the serviceTask and the error is:

10:10:09,319 [flowable-async-job-executor-thread-1] ERROR org.flowable.job.service.impl.asyncexecutor.DefaultAsyncRunnableExecutionExceptionHandler  - Job 240019 failed
org.flowable.engine.common.api.FlowableException: couldn't instantiate class org.flowable.CallTask

Any idea of what could be the problem?

Thanks,
Clara

Hi Clara,

The Flowable Task application has an embedded Flowable Engine, the Flowable REST application is not used at all. So you did everything correctly, you only need to add the JAR to the Flowable Task application WEB-INF/lib folder.

Best regards,

Tijs

1 Like

Thanks @tijs, my problem was solved :slight_smile:

Hi @tijs
I am facing the same issue, however i am on Ubuntu. Can you please confirm the path i am using indeed correct, where i am keeping my jar file.
/var/lib/tomcat8/webapps/flowable-task/WEB-INF/lib

Your help highly appreciated.

Thanks,
Sankar.

Part of the error trace from Terminal.

2018-08-30 09:59:02.319 ERROR 7355 — [nio-9999-exec-1] o.a.c.c.C.[.[.[.[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [/flowable-task] threw exception [Request processing failed; nested exception is org.flowable.common.engine.api.FlowableException: couldn’t instantiate class org.flowable.restapi] with root cause

java.lang.ClassNotFoundException: org.flowable.restapi
at org.springframework.boot.web.embedded.tomcat.TomcatEmbeddedWebappClassLoader.loadClass(TomcatEmbeddedWebappClassLoader.java:70) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1137) ~[tomcat-embed-core-8.5.32.jar:8.5.32]
at java.lang.Class.forName0(Native Method) ~[?:1.8.0_181]
at java.lang.Class.forName(Class.java:348) ~[?:1.8.0_181]
at org.flowable.common.engine.impl.util.ReflectUtil.loadClass(ReflectUtil.java:338) ~[flowable-engine-common-6.3.2-SNAPSHOT.jar:6.3.2-SNAPSHOT]
at org.flowable.common.engine.impl.util.ReflectUtil.loadClass(ReflectUtil.java:71) ~[flowable-engine-common-6.3.2-SNAPSHOT.jar:6.3.2-SNAPSHOT]
at org.flowable.common.engine.impl.util.ReflectUtil.instantiate(ReflectUtil.java:137) ~[flowable-engine-common-6.3.2-SNAPSHOT.jar:6.3.2-SNAPSHOT]

@Sankararao_Majji from the error that you are getting it shows that you want to instantiate a class org.flowable.restapi. That looks like a package to me. What is your class called? How does your BPMN XML look like?

Hi @filiphr
‘respapi’ is class that exactly looks like the one ‘CallTask’ class given above. my main intention is to call external java class from flowable-task web UI. (java class can be as simple as class with one member string variable.)

Thanks,
Sankar.

Hi Sankar,

Are you sure that restapi is the correct class name and not Restapi or something?
If you are absolutely sure the package and class name are correct and the JAR is in the WEB-INF/lib of the Flowable Task App, you can also try to place the JAR file in the Tomcat lib folder.

Best regards,

Tijs

Does it mean, every time we want to add a new java delegate for a service task, we have to “rebuild” Flowable source code. How will it work, where we do not have access to Flowable modules’s WEB-INF\lib files?

Hi,

No not at all. The idea is that you can build JAR files with the custom Java delegates and you put them in the WEB-INF/lib folder in an exploded WAR file. So no need to rebuild any Flowable source code.

Best regards,

Tijs

You meant, the WEB-INF/lib folder of flowable-task war. If so, Flowable is now tightly coupled with the Java delegate project(s). Every time I write a new set of java delegates, my newly built jar file has to be placed inside flowable-task/WEB-INF/lib. I cannot just blindly upgrade Flowable setup without considering this dependency.

Secondly, Is this approach recommended to create common delegates like CORS, Logger, De-serializer utilities etc. which are very common in most of the applications?

The Flowable Task application is an example application to let you play around with creating process instances, completing tasks etc. If you want to use Java delegates then yes they have to be available on the Flowable Task class path.

An alternative approach is to use the HTTP task and call REST endpoints with your custom logic, so that you don’t need to make the Java delegates on the Flowable Task App class path.

Best regards,

Tijs

1 Like

Hi,

I just trying use flowable (v6.5.0) as bpm engine and noticed problem as above, handlers of process steps were not found:
org.flowable.common.engine.api.FlowableException: couldn’t instantiate class x.y.z.SaveProcessInstanceListener

Caused by: org.flowable.common.engine.api.FlowableClassLoadingException: Class not found: x.y.z.SaveProcessInstanceListener
at org.flowable.common.engine.impl.util.ReflectUtil.loadClass(ReflectUtil.java:90) ~[flowable-engine-common-6.5.0.jar:6.5.0]
at org.flowable.common.engine.impl.util.ReflectUtil.instantiate(ReflectUtil.java:137) ~[flowable-engine-common-6.5.0.jar:6.5
… 123 more
Caused by: java.lang.ClassNotFoundException: x.y.z.SaveProcessInstanceListener

I’ve put .jar with classes of handlers in every /lib folders and still got this error, any idea what is wrong ?

What are you running on? Tomcat? If so, indeed the general lib or the web apps specific lib folder should do the trick.

Thank You for response…

It’s Tomcat 9.0.33, jdk11.0.6, generally I have webapps: flowable-admin etc. and additional 1 webapp (.war) based on springboot which handle steps in process.

Unfortunately it still generates the same error during option “changeState” on instance diagram.

BTW. I’ve noticed “strange behavior” when I change from step “intermediateCatchEvent” to another “intermediateCatchEvent” the diagram “paint” this target step on green and no errors in log (steps between are black), but when it’s other type of step then above errors appear.

Since the change state is triggered from Admin, that war needs to have the x.y.z.SaveProcessInstanceListener on the classpath. Are you sure it’s in the shared lib folder and not in the one from the additional webapp that handles the steps normally?

Thank You for answer.
Sorry for long silence in this topic, but I was totally involved in other project.

Unfortunately, it doesn’t work still (I use now ver 6.6.0 of engine).
Doest it mater if jar with handlers of process step is a spring boot app ? (It works fine as separate app and process is executed properly, but I want to manage some process which stucks via console).
I’ve located it in: /libs, /shared in tomcat even in unpacked folders of /flowable-rest and /flowable-ui libs and no effect, error is still the same.
Any idea how to make it works ?