Java 如何更喜欢来自 Weblogic 域的 JAR 而不是来自 weblogic 系统的 JAR

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23128846/
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-08-13 20:55:18  来源:igfitidea点击:

How to prefer JARs from Weblogic domain over those from weblogic system

javajakarta-eeweblogicclassloaderweblogic12c

提问by schoenk

I am using Weblogic Server 12.1.1and copied some JARs to my domain's libfolder. One of the JARs is a org.apache.commons.iojar. Now I have the problem that Weblogic itself comes with a different version of commons-ioin its system classpath and so I get NoSuchMethodErrors. Is there any way to configure Weblogic to prefer the libs from domain over those from Weblogic system?

我正在使用Weblogic Server 12.1.1并将一些 JAR 复制到我的域lib文件夹中。其中一个 JAR 是org.apache.commons.io罐子。现在我遇到了 Weblogic 本身在其系统类路径中带有不同版本的commons-io的问题,所以我得到NoSuchMethodErrors。有什么方法可以将 Weblogic 配置为更喜欢来自域的库而不是来自 Weblogic 系统的库?

The Filtering Classloader works only on those JARs provided with the application (WEB-INF/lib).

过滤类加载器仅适用于应用程序 ( WEB-INF/lib)提供的那些 JAR 。

采纳答案by Carles Figuera

If you need to put JARs into the domain /lib, I think you have to edit the setDomainEnv.cmd and modify PRE_CLASSPATH variable.

如果您需要将 JAR 放入域 /lib,我认为您必须编辑 setDomainEnv.cmd 并修改 PRE_CLASSPATH 变量。

Example: set PRE_CLASSPATH=C:\myinstallation\Middleware\wlserver_12.1\domains\mydomain\lib\myjar.jar

示例:设置 PRE_CLASSPATH=C:\myinstallation\Middleware\wlserver_12.1\domains\mydomain\lib\myjar.jar

But, if is possible to put JARs in WEB-INF/lib or APP-INF/lib, then use @Blekit solution, it's cleaner.

但是,如果可以将 JAR 放在 WEB-INF/lib 或 APP-INF/lib 中,那么使用 @Blekit 解决方案,它会更干净。

回答by Blekit

Use one of follwing options in weblogic.xmldescriptor:

weblogic.xml描述符中使用以下选项之一:

  • prefer-application-packages
  • prefer-web-inf-classes
  • prefer-application-packages
  • prefer-web-inf-classes

Details are described here.

此处描述详细信息。

回答by ralferic

For completeness, i must say that putting commons-io into the domain/lib folder is a bad solution. The problem you describe is a good reason not to put widely used libraries into this folder. The problem might be circumvented by an even worse idea: moving that library higher up in the classloader hierarchy. If you insist on excluding commons-io from your application deliverables, you might install commons-io as an endorsed lib in the jdk. (see here) This would nail down your version of commons-io for every application including weblogic itself. Of course, this would be a problem if you need to contact weblogic support.

为了完整起见,我必须说将 commons-io 放入 domain/lib 文件夹是一个糟糕的解决方案。您描述的问题是不将广泛使用的库放入此文件夹的一个很好的理由。这个问题可能会被一个更糟糕的想法所规避:在类加载器层次结构中将该库移到更高的位置。如果您坚持将 commons-io 从您的应用程序交付中排除,您可以安装 commons-io 作为 jdk 中的认可库。(请参阅此处)这将为每个应用程序(包括 weblogic 本身)确定您的 commons-io 版本。当然,如果您需要联系 weblogic 支持,这将是一个问题。