1

I've included a .jar in my maven project writing this in pom.xml:

<dependencies>
    <dependency>
        <groupId>org.loopingdoge.acme.model</groupId>
        <artifactId>acme-model</artifactId>
        <version>1.0.0</version>
        <scope>system</scope>
        <systemPath>${basedir}/src/main/webapp/WEB-INF/lib/acme-model.jar</systemPath>
    </dependency>
</dependencies>

acme-model.jar contains org.loopingdoge.acme.model.House but this cast

public class HouseAdder implements JavaDelegate {

    public void execute(DelegateExecution delegateExecution) throws Exception {
        House house = (House) delegateExecution.getVariable("house");
    }
}

gives me this error when deployed on a Wildfly server:

18:50:20,255 ERROR [org.camunda.bpm.engine.context] (default task-45) ENGINE-16004 Exception while closing command context: org.loopingdoge.acme.model.House cannot be cast to org.loopingdoge.acme.model.House: java.lang.ClassCastException: org.loopingdoge.acme.model.House cannot be cast to org.loopingdoge.acme.model.House at org.loopingdoge.acme.services.HouseAdder.execute(HouseAdder.java:13)

Devid Farinelli
  • 7,514
  • 9
  • 42
  • 73

3 Answers3

2

Such cases happens when a class will be loaded over different classloaders. java make them distinct even if package and classname are identical.

You need to find out on which ways this class will be loaded. As first step, find the jars which contains that class.

or/and read this on SO

stefan bachert
  • 9,413
  • 4
  • 33
  • 40
1

Ran into the same problem. Further analysis showed that two different class loaders were used, as stated in this thread already. In my case the culprit was devtools of spring boot, a tool which likely many will have active in their pom. Seems that devtools doesn't play well with (in my case) camunda java delegates with embedded camunda engine.

tge
  • 11
  • 3
  • This has resolved my issue, when using Camunda Embedded with DevTools. Disabling devtools and restarting application. – Jatish Jun 18 '20 at 04:54
0

I guess that you have the class in multiple places, e.g. packaged the jar within WildFly and the WAR you deploy. Check that you have the class only one time on the classpath.

By the way: Better not use system dependencies if not absolutely necessary. This is what maven repositories are for.

Bernd Ruecker
  • 970
  • 5
  • 6