java Weblogic 12c:Jersey 的 Prefer-web-inf-classes 和 preferred-application-packages
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36292980/
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
Weblogic 12c : Prefer-web-inf-classes and prefer-application-packages for Jersey
提问by Azimuts
I have to use both (oddly enough ..) prefer-web-inf-classes
and prefer-application-packages
properties of weblogic.xmlon a Weblogic 12c Server (12.2.1)
我必须在Weblogic 12c 服务器 (12.2.1)上同时使用(奇怪的是 ..)prefer-web-inf-classes
和weblogic.xml 的prefer-application-packages
属性
It is REST application based on Jersey 1.9. ( Jersey 1.x JAX-RS RI) and Guice.
它是基于 Jersey 1.9 的 REST 应用程序。( Jersey 1.x JAX-RS RI) 和 Guice。
1. Why use :prefer-web-inf-classes
1. 为什么使用 :prefer-web-inf-classes
If you have more than one WAR you have to place at the level of war/lib the libraries for guice-jersey / guice , other way you get an Multibindings Error.
如果您有多个 WAR,则必须将 guice-jersey / guice 的库置于 war/lib 级别,否则您会得到Multibindings Error。
It must be indicated also the prefer-web-inf-classes
to true
.
还必须指明prefer-web-inf-classes
to true
。
This way it works properly!
这样它就可以正常工作了!
I have tried to work in the same way using prefer-application-package
s with packages (com.sun.jersey.guice.spi.container.servlet
, com.google.inject.servlet
, etc...) but no way.
我已经尝试使用工作以同样的方式prefer-application-package
s的包(com.sun.jersey.guice.spi.container.servlet
,com.google.inject.servlet
,等...),但没有办法。
Note: It is not possible to exclude this libraries at EARlevel.
注意:无法在EAR级别排除此库。
2. Why use :prefer-application-packages
2. 为什么使用 :prefer-application-packages
To use Jersey 1.x JAX-RS RI on Weblogic 12c (12.2.1) so I have to indicate the following packages (other way Weblogic uses Jersey 2, and different version of Hymanson libraries, etc.)
要在 Weblogic 12c (12.2.1) 上使用 Jersey 1.x JAX-RS RI,我必须指明以下包(Weblogic 使用 Jersey 2 的其他方式,以及不同版本的 Hymanson 库等)
It works perfectly on Jersey 1.X if it is indicated this way.. I have probed two war separately, and works fine... but, remember my friend I have two war..so....
如果以这种方式指示,它可以在 Jersey 1.X 上完美运行。. 我分别探讨了两场War,并且工作正常......但是,请记住我的朋友我有两场War......所以......
Summary
概括
I can not use both properties (deploying error for using both properties on the weblogic.xml..), but it's needed :
我不能同时使用这两个属性(在 weblogic.xml 上使用这两个属性时出现部署错误..),但它是必需的:
- For the problem with Guice Filter, need to put
prefer-web-inf-classes
totrue
to useguice-servlet.jar
/jersey-guice.jar
at war-lib level. - To work with Jersey 1.x, need to use .....
prefer-application-package
- 对于吉斯过滤器,需要的问题提出
prefer-web-inf-classes
来true
使用guice-servlet.jar
/jersey-guice.jar
在 War-lib的水平。 - 要使用 Jersey 1.x,需要使用 .....
prefer-application-package
Question: How to combine both to use one of them??
问题:如何将两者结合使用其中之一?
采纳答案by Azimuts
After all
毕竟
- Use just
prefer-web-inf-classes
totrue
. If you use this, you don't need to use
prefer-application-packages
....BUT ENSURE that you have the correct libraries at war /ear level.The problem was:
- 仅
prefer-web-inf-classes
用于true
. 如果你使用它,你不需要使用
prefer-application-packages
......但确保你在 war /ear 级别拥有正确的库。问题是:
The Project had a dependency with Jersey 2 (based on Swaggerfor Jersey 2.X ...) So via Swagger dependencies (swagger-jersey2-jaxrs
), Jersey 2 libraries was packaged on ear/war... and so prefer-web-inf-classes
HAS NO EFFECT!
该项目与 Jersey 2 有依赖关系(基于Swaggerfor Jersey 2.X ...)所以通过 Swagger 依赖项 ( swagger-jersey2-jaxrs
),Jersey 2 库被打包在 ear/war ......所以prefer-web-inf-classes
没有效果!
After removing the dependency all was resolved!
删除依赖后,一切都解决了!
At same the level (classpath or ear lib, or war lib) should not exist different versions of the same library.
在同一级别(类路径或耳库或War库)不应存在同一库的不同版本。
回答by Gajendra Singh
Hello, world! Hi, There are two way to resolve this problem.
You can used to combine both file in to one file and call it based on choose tag as requirements.
You can just write tags to merge or import/ include your xml file in to one. Example shown. Hint: Do google how to merge and call xml file based on condition.
你好世界!你好,有两种方法可以解决这个问题。
您可以将两个文件合并为一个文件,并根据选择标签作为要求调用它。
您可以只编写标签来合并或导入/包含您的 xml 文件。示例显示。提示:谷歌如何根据条件合并和调用xml文件。