简体   繁体   English

卡蒙达(Camunda):不能投放到(同一班级)

[英]Camunda: cannot be cast to (same class)

I've included a .jar in my maven project writing this in pom.xml : 我在maven项目中包含了一个.jar ,并在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 acme-model.jar包含org.loopingdoge.acme.model.House但此acme-model.jar org.loopingdoge.acme.model.House

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: 部署在Wildfly服务器上时,出现此错误:

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) 18:50:20,255错误[org.camunda.bpm.engine.context](默认任务45)ENGINE-16004关闭命令上下文时发生异常:org.loopingdoge.acme.model.House无法转换为org.loopingdoge.acme .model.House:java.lang.ClassCastException:org.loopingdoge.acme.model.House无法转换为org.loopingdoge.acme.model.House,位于org.loopingdoge.acme.services.HouseAdder.execute(HouseAdder.java: 13)

Such cases happens when a class will be loaded over different classloaders. 当通过不同的类加载器加载类时,会发生这种情况。 java make them distinct even if package and classname are identical. 即使包和类名相同,Java也会将它们区分开。

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 或/然后在SO上阅读

I guess that you have the class in multiple places, eg packaged the jar within WildFly and the WAR you deploy. 我猜您在多个地方都有该课程,例如,将Jar打包在WildFly中,并将您部署的WAR打包。 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. 这就是Maven存储库的用途。

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. 在我的案例中,罪魁祸首是弹簧靴的devtools,这可能是许多人在pom中活跃的工具。 Seems that devtools doesn't play well with (in my case) camunda java delegates with embedded camunda engine. 似乎devtools与嵌入式camunda引擎的camunda java委托不能很好地配合(在我的情况下)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM