2

我的 EAR 项目中有一个LinkageErrorWildfly 10.1。该项目包含一个 ejb 和一个 web 子项目。Maven的依赖管理。Gson 包被添加到父舞会和两个子项目的舞会中。

无法弄清楚第二个 gson 类的加载位置。关于如何解决这个问题的任何建议?

15:02:14,242 ERROR [io.undertow.request] (default task-2) UT005023: 
Exception handling request to /Trigger-Server-web/event/quote:     
java.lang.LinkageError: loader constraint violation: when resolving 
interface method "de.company.triggerserver.ejb.EventProcessingLocal.processEvent(Ljava/lang/String;Lcom/google/gson/JsonObject;)Z" the class loader (instance of org/jboss/modules/ModuleClassLoader) of the current class, de/company/triggerserver/web/EventServlet, and the class loader (instance of org/jboss
/modules/ModuleClassLoader) for the method's defining class, de/company
/triggerserver/ejb/EventProcessingLocal, have different Class objects for the type com/google/gson/JsonObject used in the signature
4

1 回答 1

2

此问题是由于在 WAR 文件的 EAR/lib 目录和 WEB-INF/lib 目录中都有 Gson jar 的副本。

因此,诀窍是摆脱 WAR 文件中的那个。

简单的解决方案是<scope>provided</scope>在 web 模块的 pom.xml 文件中标记它的依赖关系。

一种更复杂的方法是利用 maven-ear-plugin 的能力来构建带有“skinny WARS”的 EAR 文件,如创建 Skinny WARs中所述。这实质上会在 EAR 组装过程中从 Web 模块的 WEB-INF/lib 目录中删除重复的 jar。

您可能会发现第二种方法更好,因为您的 EAR 文件构建中可能有其他 jar 的多个副本,并且您将使用第一种方法一次发现这些副本。

于 2016-12-05T08:22:13.953 回答