java 如何强制 jboss 从 webapp 库中的 jars 加载类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4947388/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 08:44:31  来源:igfitidea点击:

How to force jboss to load classes from jars in webapp's lib

javajakarta-eedeploymentjboss

提问by Jboss Crezy

I am trying to deploy my web application on jboss-6.0.0Final, which is currently deployed on apache tomcat. I have two jars one that contains same package which is org.apache.axis. I am putting one jar in <Jboss-home>/server/default/lib& another jar in <my-app-war>WEB-INF/lib.

我正在尝试将我的 Web 应用程序jboss-6.0.0Final部署在上,该应用程序当前部署在apache tomcat. 我有两个罐子,一个罐子包含相同的包org.apache.axis。我把一个罐子放进去<Jboss-home>/server/default/lib,另一个罐子放进去<my-app-war>WEB-INF/lib

It is required to put both jars in the class path. No way to remove one of the jar. So I need to keep both jars. & It is giving me following error

需要将两个 jar 都放在类路径中。没有办法取出一个罐子。所以我需要保留两个罐子。&它给了我以下错误

java.lang.ClassCastException: org.apache.axis.attachments.AttachmentsImpl cannot be cast to org.apache.axis.attachments.Attachments
    at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
    at org.apache.axis.client.Call.invoke(Call.java:1828)

I think it is due to conflict of same classes in two different jars.

我认为这是由于两个不同 jar 中相同类的冲突。

Now, I want to know the way by which I can force jboss to load classes of this particular package from axis.jar exist in /WEB-INF/lib.

现在,我想知道如何强制 jboss 从 /WEB-INF/lib 中存在的axis.jar 加载这个特定包的类。

How can I do that?

我怎样才能做到这一点?

回答by JavaSheriff


This helped me:
http://www.mastertheboss.com/jboss-configuration/solving-jboss-5-classloading-issues

Explode your war,

In your Exploded WAR web-inf directory add this xml file: jboss-classloading.xml
with content:
(domain is your war name)


这帮助了我:
http://www.mastertheboss.com/jboss-configuration/solving-jboss-5-classloading-issues

爆炸你的War,

在你引爆WAR的WEB-INF目录下添加此XML文件:的jboss-classloading.xml
与内容:(
域是你的War名称)

 <classloading xmlns="urn:jboss:classloading:1.0"
            name="mywar.war"
            domain="mywar_domain"  <!-- (domain is your war name) -->
            parent-domain="Ignored"
            export-all="NON_EMPTY"
            import-all="true">
</classloading>

回答by Pratik Ambani

I'll share quite simple and straight forward process which I had followed when I came across same situation.

我将分享我遇到相同情况时遵循的非常简单和直接的过程。

1> Create a jboss-web.xmlfile.

1> 创建一个jboss-web.xml文件。

  <class-loading java2classloadingcompliance="false">
  <loader-repository>
      com.rts:archive=DTH_PROD.war
      <loader-repository-config>
          java2ParentDelegation=false
      </loader-repository-config>
  </loader-repository>
  </class-loading>
</jboss-web>

Points:,

积分:,

  • Begin the xml with tag which is not visible in the code I'm posting Check 3rd line of above code,
  • com.rts- This is your package name.
  • DTH_PROD.war- Name of bundle you wish to keep
  • 使用在我发布的代码中不可见的标记开始 xml 检查上面代码的第 3 行,
  • com.rts- 这是您的包名称。
  • DTH_PROD.war- 您希望保留的包的名称

2> Now place this xml file into WEB-INF directory of your project and voilla!!

2> 现在把这个 xml 文件放到你的项目的 WEB-INF 目录中,瞧!!

Further more you may wish to refer this articlefor detailed info. Also comment below if you face any difficulty solving this.

此外,您可能希望参考这篇文章以获取详细信息。如果您在解决此问题时遇到任何困难,请在下面发表评论。