Java LinkageError on Wildfly build by maven



我在wildfly 10.1上的耳朵项目中有一个LinkageError。该项目包含一个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

此问题是由在ear/lib目录中包含gson jar的副本和战争文件的web-inf/lib目录引起的。

因此,诀窍是摆脱战争档案中的一个。

简单的解决方案是将其依赖性标记为Web模块的pom.xml文件中的<scope>provided</scope>

一种更复杂的方法是利用Maven-Ear-Plugin用"瘦战争"构建耳朵文件的能力,如创造瘦战时所描述的那样。这本质上可以从您的Web模块的Web-Inf/Lib目录中删除重复的JAR。

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

最新更新