I have a LinkageError
in my EAR Project on Wildfly 10.1.
The project contains an ejb and a web subproject. Dependency Management by Maven. Gson Package is added in parent prom and in proms of both subprojects.
Can't figure out where the second gson class gets loaded. Any suggestions on how to solve this?
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
This problem is caused by having a copy of the Gson jar in both the EAR/lib directory and the WEB-INF/lib directory of your WAR file.
Therefore the trick is to get rid of the one in the WAR file.
The simple solution is to mark it's dependency as <scope>provided</scope>
in the web module's pom.xml file.
A more sophisticated approach is to make use of the maven-ear-plugin's ability to build EAR files with "skinny WARS" as described in Creating Skinny WARs. This essentially removes duplicate jar from your web module's WEB-INF/lib directory during the EAR assembly process.
You may find the second approach better because it's possible that you have multiple copies of other jars in your EAR file build, and you will be discovering these one at a time with the first approach.