如何处理 Glassfish 包含的库与应用程序提供的库崩溃的情况?
我的 CXF JAX-RS 应用程序使用 jackson 将 POJO 编组为 JSON。这在大多数情况下都有效,但有一天,在编组深度嵌套对象时,它因 NPE 而失败。
经过一番调查后,我发现 Jackson 已包含在 Glassfish 3 中(通过 Jersey),并且删除了 jackson-core-asl.jar、jackson-jaxrs.jar、jackson-mapper-asl.jar
和 < code>jackson-xc.jar 一切都很顺利。我猜想 Jackson 1.7.1(包含在 GF3 中)有一些错误,这些错误已在我的应用程序(1.8)附带的版本中修复。
现在的问题是,为什么我一开始就必须这样做?我认为我的 war 文件中包含的库应该优先于 Glassfish 的 /modules
目录中的任何库。
有没有比从应用程序服务器中删除 jar 更干净的方法来做到这一点?也许还有其他应用程序依赖于这些 jar...
顺便说一下,我们的 GF2 容器仍然存在问题,但我在 /lib
文件夹中找不到任何 jackson 库(没有像 GF3 那样的 /modules
文件夹)。关于杰克逊在《GF2》中可能藏身何处的任何线索(如果有的话)?
A CXF JAX-RS application I have uses jackson to marshal POJOs to JSON. This works for the most part, but the other day it failed with a NPE when marshalling a deeply nested object.
After some investigation I found out that Jackson was included in Glassfish 3 (through Jersey) and after removing jackson-core-asl.jar, jackson-jaxrs.jar, jackson-mapper-asl.jar
and jackson-xc.jar
everything worked beautifully. I guess that Jackson 1.7.1 (included in GF3) had some bug that was fixed in the version shipped with my application (1.8).
Now the question is, why did I even have to do this in the first place? I would have thought libraries that are included in my war files should take presedence over any libraries in Glassfish's /modules
directory.
Is there a cleaner way to do this than removing jars from the app server? Maybe there are other applications that depend on these jars ...
On a side note, the problem still exists with our GF2 container, but I cannot find any jackson libraries in the /lib
folder (there is no /modules
folder like in GF3). Any clues on where Jackson might be hiding in GF2 (if at all)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
告诉 Web 应用程序类加载器首选 WAR 提供的 JAR。
添加 WEB-INF/sun-web.xml (或 WEB-INF/glassfish-web.xml):
请参阅 http://jersey.java.net/nonav/documentation/latest/glassfish.html#d4e1927
Tell the Webapp classloader to prefer JARs provided by your WAR.
Add in your WEB-INF/sun-web.xml (or WEB-INF/glassfish-web.xml):
See http://jersey.java.net/nonav/documentation/latest/glassfish.html#d4e1927
考虑使用:
asadmin deploy --libraries ...
参考:http://blogs .oracle.com/alexismp/entry/more_with_deploy_libraries
consider using :
asadmin deploy --libraries ...
Ref: http://blogs.oracle.com/alexismp/entry/more_with_deploy_libraries
Jackson 包含在 Jersey 和 Hadoop 中,如果您可能正在运行 Jersey 或与 Hadoop 系统交互;并且包含的版本通常很旧。所以这可能是“古老的杰克逊”问题的根源之一。
Jackson is included by Jersey and Hadoop, if you might be running Jersey or interact with Hadoop system; and versions included are often old. So this could be one source for "ancient Jackson" problems.