Java LinkageError while deploying to weblogic

时间:2015-10-29 15:54:57

标签: java maven weblogic axis linkageerror

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...

3 个答案:

答案 0 :(得分:3)

好的,我解决了这个问题。我找到了冲突的依赖项;

回顾:

使用

  

WebLogic的web应用程序/容器描述符

对我不起作用:

  

prefer-web-inf-classes = true

已经设置并将其更改为更喜欢应用程序包只会导致更多麻烦,因为项目已经依赖于prefer类配置。

解决方案:

我使用findjar来查找哪个jar是我的QName resides并将这些jar放在我的记忆中。

然后使用

  

mvn依赖:树

我得到了项目的所有依赖项和子项依赖项(不会发布它,因为POM很大)。

我注意到他们的名字中有两个带有'stax'的依赖项。一个'官方'stax jar(xmlbeans的子依赖)和一个来自genronimo(axiom的sub依赖)。所以我做了一些研究,发现geronimo stax是对原始stax jar的实现/改编,因此都包含QName。 我从依赖列表中删除了原始的stax:

    <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>

希望有所帮助:)

答案 1 :(得分:1)

您可以通过将prefer-web-inf-classes添加到WAR文件中的weblogic.xml来告诉WebLogic使用您的应用程序类。

<weblogic-web-app>
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
</weblogic-web-app>

答案 2 :(得分:1)

WebLogic还允许您指定应用程序与WLS类路径中使用的程序包:

<weblogic-web-app>
  <container-descriptor>
    <prefer-application-packages>
      <package-name>org.apache.commons.*</package-name>
      <package-name>org.apache.log4j.*</package-name>
      <package-name>org.slf4j.*</package-name>
    </prefer-application-packages>
  </container-descriptor>
</weblogic-web-app>

prefer-web-inf-classes表示应用程序中打包的内容始终优先于WebLogic的设置,这可能是也可能不是一件好事。