简体   繁体   English

部署到weblogic时的Java LinkageError

[英]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. 我正在开发一个大型应用程序,我刚刚在轴的帮助下添加了一个由eclipse生成的新Web服务。 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). 应用程序在我的开发环境中运行正常(应用程序由jetty托管)但是现在我在weblogic中运行我的应用程序时遇到了麻烦(需要部署应用程序)。 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 Axis依赖项包含类:org.apache.axis.client.Service,它位于javax.xml.rpc.Service接口之后。
  • My Weblogic provided the interface: javax.xml.rpc.Service 我的Weblogic提供了接口:javax.xml.rpc.Service
  • Since they are in a different path (application and weblogic) they are loaded by different classloaders 由于它们处于不同的路径(应用程序和weblogic),因此它们由不同的类加载器加载

1st question: Are my observations correct? 第一个问题:我的观察是否正确?

2nd question: What can I do/try to resolve this? 第二个问题:我能做什么/尝试解决这个问题?

Extra information: 额外的信息:

  • Using Maven. 使用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). 为了确保Weblogic加载的所有依赖项在我们的开发环境中也可用,我们将wlsfullclient.jar添加为依赖项(仅在我们的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. 由于我们的weblogic服务器被很多项目使用,我不能只将Axis jar添加到weblogic路径。
  • I found a similar issue already on Stack: How to deal with LinkageErrors in Java? 我在Stack上发现了一个类似的问题: 如何处理Java中的LinkageErrors? .
    • 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". 他们的解决方案对我来说并不清楚,尽管我对Alex Miller的回复感兴趣,具体来说:“这可能意味着将其从类路径中删除并加载为插件”。
      • Does this apply on the application side or is this the web logic side? 这适用于应用程序端还是Web逻辑端?
  • If more information is required I will gladly provide it. 如果需要更多信息,我很乐意提供。

EDIT: I have a weblogic.xml in my project with the following content: 编辑:我的项目中有一个weblogic.xml,内容如下:

<?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: 我的WAR文件的结构如下:

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

Ok I solved the issue. 好的,我解决了这个问题。 I found the conflicting dependencies; 我发现了冲突的依赖关系;

Recap: 概括:

Using the 使用

weblogic-web-app/container-descriptor WebLogic的web应用程序/容器描述符

did not work for me: 不适合我:

prefer-web-inf-classes = true 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. 已经设置并将其更改为更喜欢应用程序包只会导致更多麻烦,因为该项目已经依赖于prefer类配置。

Solution: 解:

I used findjar for looking up in which jar's my QName resides and put these jar's in my memory. 我使用findjar来查找我的QName所在的 jar,并把这些jar放在我的记忆中。

Then by using 然后通过使用

mvn dependency:tree mvn依赖:树

I got all the dependencies and sub dependencies of my project (wont post it because the POM is BIG). 我得到了我的项目的所有依赖项和子依赖项(不会发布它因为POM很大)。

I noticed that there were two dependencies with 'stax' in their name. 我注意到他们的名字中有两个带有'stax'的依赖项。 One 'official' stax jar (sub dependency of xmlbeans) and one from genronimo (sub dependency of axiom). 一个'官方'stax jar(xmlbeans的子依赖)和一个来自genronimo(axiom的sub依赖)。 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. 所以我做了一些研究,发现geronimo stax是对原始stax jar的实现/改编,因此都包含QName。 I removed the original stax from my dependency list: 我从依赖列表中删除了原始的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>

Hope it helps :) 希望能帮助到你 :)

You can tell WebLogic to use your application classes by adding prefer-web-inf-classes to the weblogic.xml in your WAR file. 您可以通过将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>

WebLogic will also let you specify which packages to use from your app vs. from the WLS classpath: 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 means that what's packaged in the app always takes precedence over WebLogic's settings, which may or may not be a good thing. prefer-web-inf-classes意味着应用程序中打包的内容始终优先于WebLogic的设置,这可能是也可能不是一件好事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM