处理重复的完全合格的名称 [英] Dealing With Duplicate Fully Qualified Names
问题描述
现在,这两个库都以jar形式导入,似乎在某些环境(命令行调用,Eclipse)找到正确的类,在其他(Maven)中找到错误的类,我得到一个缺少的方法异常。如果没有找到解决方案,我可以回到重新整理这些库中的一个并重建jar,但是我宁愿不用每次图书馆更新时重复这个工作。
编辑:如果有人再次看到这个问题并且很困惑,那么我接受了Dave Newton的回答,因为如果你勤奋地抓住这个问题,那么这将是正确的方法编写所有的代码写完所有的代码后自动修复导入,似乎是不可能的,因为我怀疑。
你要么阴暗,并删除重复,或...
当您有多个实现时,您受到类加载器的怜悯,除非您采取主动步骤来减轻重复。
进一步讨论这个SO问题。
Like the title says, is there a way to deal with this? I have imported two separate third party libraries and they have a fully qualified class name conflict.
Right now both libraries are being imported in jar form, and it appears that in some environments (command line invocation, Eclipse) the correct class is found and in others (Maven) the wrong class is found and I get a missing method exception. If no solution can be found, I can fall back to re-factoring one of these libraries and rebuilding the jar, but I would rather not have to repeat that work every time the library has an update.
Edit: If anyone sees this later and is confused, I accepted Dave Newton's answer because it would be the correct way to do this if you were diligent enough to catch this problem before writing all of your code. Fixing the imports automagically after writing all the code appears to be impossible, as I suspected.
You either shade, bust them apart and remove the dupes, or...
When you have multiple implementations you are at the mercy of your classloader(s) unless you take active steps to mitigate the dupes.
Further discussion at this SO question.
这篇关于处理重复的完全合格的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!