问题
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>
回答1:
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).
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.
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.
If you are trying to replace an Apache stack with a Jersey stack, then you (probably) need to change your webapp in some way:
- Replace explicit use of classes in your code (normal and reflective).
- Remove the JARs for the "old" stack from your webapp.
Also, trying to run Apache specific code inside a Jersey container is asking for trouble.
来源:https://stackoverflow.com/questions/27536024/prefer-package-within-prefer-application-packages