Search code examples
javamavenweblogicaxislinkageerror

Java LinkageError while deploying to weblogic


I am working on a big application and I just added a new web service generated by eclipse with the help of axis. The application runs fine in my development environment (where the application is hosted by jetty) but now I am having trouble when running my application in weblogic (where the application needs to be deployed). The error I am getting is:

java.lang.LinkageError: loader constraint violation in interface
itable initialization: when resolving method
"org.apache.axis.client.Service.getServiceName()Ljavax/xml/namespace/QName;"
the class loader (instance of
weblogic/utils/classloaders/ChangeAwareClassLoader) of the current
class, org/apache/axis/client/Service, and the class loader (instance
of sun/misc/Launcher$AppClassLoader) for interface
javax/xml/rpc/Service have different Class objects for the type
getServiceName used in the signature

This issue is delaying development for days already. As I understand from looking on the web:

  • My Axis dependency contains the class: org.apache.axis.client.Service which follows the javax.xml.rpc.Service interface.
  • My Weblogic provided the interface: javax.xml.rpc.Service
  • Since they are in a different path (application and weblogic) they are loaded by different classloaders

1st question: Are my observations correct?

2nd question: What can I do/try to resolve this?

Extra information:

  • Using Maven.
  • To make sure all dependencies loaded by Weblogic are also available in our development environment we added the wlsfullclient.jar as a dependency (only in our dev env).
  • Since our weblogic server is used by a lot of projects I can not just add the Axis jar to the weblogic path.
  • I found a similar issue already on Stack: How to deal with LinkageErrors in Java?.
    • Their solution is not clear for me though I am interested in Alex Miller's reply, specifically: "That may mean removing it from the classpath and loading as a plugin".
      • Does this apply on the application side or is this the web logic side?
  • If more information is required I will gladly provide it.

EDIT: I have a weblogic.xml in my project with the following content:

<?xml version='1.0' encoding='UTF-8'?>
  <weblogic-web-app >
    <container-descriptor>
      <prefer-web-inf-classes>true</prefer-web-inf-classes>
    </container-descriptor>
  <context-root>auditgui</context-root>
</weblogic-web-app>

The structure of my WAR file is as follows:

file.war
    |--crossdomain.xml
    |--robots.txt
    |--META-INF
    |   \--MANIFEST.MF
    |--WEB-INF
    |   |--classes
    |   |   |--com
    |   |   |   \--...
    |   |   |--spring
    |   |   |   |--main-context.xml
    |   |   |   \--security-context.xml
    |   |   \--environment-beans.xml
    |   |--lib
    |   |   \--multiplejars.jar
    |   |--spring
    |   |   |--raw-servlet-context.xml
    |   |   |--root-context.xml
    |   |   \--servlet-context.xml
    |   |--web.xml
    |   \--weblogic.xml
    |--css
    |   \--multipleCSSFiles.css
    |--js
    |   \--multipleJSFiles.js...
    |--img
    |   \--muultipleImages.png...
    \--multipleHTMLFiles.html...

Solution

  • Ok I solved the issue. I found the conflicting dependencies;

    Recap:

    Using the

    weblogic-web-app/container-descriptor

    did not work for me:

    prefer-web-inf-classes = true

    was already set and changing it to prefer application packages only caused more trouble since the project already depended on the prefer classes configuration.

    Solution:

    I used findjar for looking up in which jar's my QName resides and put these jar's in my memory.

    Then by using

    mvn dependency:tree

    I got all the dependencies and sub dependencies of my project (wont post it because the POM is BIG).

    I noticed that there were two dependencies with 'stax' in their name. One 'official' stax jar (sub dependency of xmlbeans) and one from genronimo (sub dependency of axiom). So I did some research and found out that the geronimo stax is an implementation/adaption on the original stax jar and therefore both contain QName. I removed the original stax from my dependency list:

        <dependency>
            <groupId>org.apache.xmlbeans</groupId>
            <artifactId>xmlbeans</artifactId>
            <version>2.5.0</version>
            <!-- Excluding XMLBean's STAX because we want to use axiom/geronimo-stax -->
            <exclusions>
                <exclusion>
                    <groupId>stax</groupId>
                    <artifactId>stax-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    

    Hope it helps :)