首选应用程序包中的首选程序包 [英] Prefer package within prefer-application-packages

查看:169
本文介绍了首选应用程序包中的首选程序包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以强制将WAR中的com.sun.jersey。*用于WAR中的org.apache。*?还是根据订单自动完成?

Is there a way to force com.sun.jersey.* in the WAR to be used over org.apache.* in the WAR? Or is this done automatically based on the order?

<prefer-application-packages>
    <package-name>com.sun.jersey.*</package-name>
    <package-name>org.apache.*</package-name>
    <package-name>antlr.*</package-name>
    <package-name>javax.ws.rs.*</package-name>
</prefer-application-packages>


推荐答案

这个问题并没有告诉我们您实际上是什么试图做。但是,我猜测您正在尝试/希望让Weblogic使用一个包树(球衣)中的类来替换另一棵树(Apache)中的类。

This question doesn't tell us what you are actually trying to do. However, I'm guessing that you are trying / hoping to get Weblogic to use classes in one package tree (jersey) as replacements for classes in another tree (apache).

那是行不通的。假设您的源代码引用了 org.apache。* 类,则类加载器将查找具有源代码指定的完全合格的类名称的类。它不会将一个程序包树中的类即时替换为其他程序包树中的类。如果以反射方式加载类,则同样适用...除非您的应用程序本身重写了合格的类名字符串。

That won't work. Assuming that your source code has references to org.apache.* classes, the class loader is going to look for classes with exactly the fully qualified class names that the source code specified. It won't do on-the-fly substitution of classes in one package tree for classes in a different package tree. The same applies if the classes are loaded reflectively ... unless your application itself rewrites the qualified class name string.

prefer-application-packages 元素正在解决另一个问题。它正在做的是在其他地方查看这些课程。 JAR文件可以部署在容器级别或Web应用程序中。默认情况下,如果您已经在容器级别和Webapp级别的JAR中部署了软件包,则将加载容器级别的版本。此元素列出了应在其中加载Web应用级版本的软件包。

The prefer-application-packages element is solving a different problem. What it is doing is to look in a different place for the classes. JAR files can be deployed at the container level or within a webapp. By default, if you have a package that has been deployed in both container-level and webapp-level JARs, the container-level version will be loaded. This element lists packages where the webapp-level version should be loaded instead.

如果您尝试替换Apache堆栈使用Jersey堆栈,则您(可能)需要以某种方式更改您的Web应用程序:

If you are trying to replace an Apache stack with a Jersey stack, then you (probably) need to change your webapp in some way:


  • 在代码中替换类的显式使用(

  • 从您的Web应用程序中删除旧堆栈的JAR。

此外,尝试在Jersey容器内运行Apache特定代码也会带来麻烦。

Also, trying to run Apache specific code inside a Jersey container is asking for trouble.

这篇关于首选应用程序包中的首选程序包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆