【问题标题】:Java LinkageError on Wildfly build by mavenWildfly 上的 Java LinkageError 由 maven 构建
【发布时间】:2016-12-04 14:13:10
【问题描述】:

我在 Wildfly 10.1 上的 EAR 项目中有一个 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

【问题讨论】:

    标签: java maven jakarta-ee jboss linkageerror


    【解决方案1】:

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

    因此,诀窍是去掉 WAR 文件中的那个。

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-01
      • 1970-01-01
      • 2015-12-30
      • 1970-01-01
      • 2017-10-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多