如何处理类路径冲突
在我的项目中,我同时使用 glassfish-embedded 3.1.1 和 guava lib...问题是 glassfish 附带了 guava 的旧实现(即 google-collections)...
这会导致运行时出现 NoSuchMethodError,例如,当使用稍后在 guava 中引入的 Lists.reverse() 或 Sets.newIdentityHashSet() 时。
我找不到任何解决方案来解决这个问题...(唯一的方法是手动将 glassfish jar 中的 com/google 类目录删除...)
In my project, I'm using both glassfish-embedded 3.1.1 and the guava lib... The problem is that glassfish comes with the old implementation of guava (ie google-collections)...
This results in NoSuchMethodError at runtime, for example when using Lists.reverse(), or Sets.newIdentityHashSet() which were introduced later in guava.
I don't find any solution to solve this... (the only one is to manually trash the com/google classes directory in the glassfish jar...)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过指定以下内容来克服这个问题。阅读类加载器一章的委托部分。
检查此 SO 帖子,了解 Java EE 应用程序中的类加载情况:Java EE 类加载标准
You can overcome this be specifying the below. Read the Delegation section of the Class Loaders chapter.
Check this SO post for class loading in Java EE apps in general: Java EE class loading standard
Glassfish 永远不应该在自己的 jar 中包含 com.google 类。那是一个错误。
更新[@sly7_7]:看来 glassfish 不再在自己的罐子中包含番石榴,但它取决于番石榴工件。这应该可以解决问题。
感谢@JagWire 指出这一点。
Glassfish should never have included com.google classes in their own jar. That was an error.
UPDATE[@sly7_7]: It seems like glassfish does not include guava in their own jar anymore, but it depends on the guava artifact instead. This should resolve the problem.
Thanks to @JagWire for pointing this.
我能够通过使用以下 Glassfish v4 版本来消除错误:
http://grepcode.com/snapshot/maven.java.net/content/groups/promoted/org.glassfish.main.extras/glassfish-embedded-all/4.0.1-b01
可能值得一看。
I was able to make the error go away by using the following Glassfish v4 build:
http://grepcode.com/snapshot/maven.java.net/content/groups/promoted/org.glassfish.main.extras/glassfish-embedded-all/4.0.1-b01
Might be worth taking a look.