问题描述
我正在使用 ant 构建 java jar 文件.我需要使用 "zipfileset src="xxx.jar" "zipfileset src="yyy.jar" 包含额外的 jars,并且 xxx.jar 和 yyy.jar 都有具有相同完全限定类名称的类.因此生成的 jar 文件具有重复的类名.重复可能有什么影响?
I am building java jar file using ant. I need to include additional jars using "zipfileset src="xxx.jar" "zipfileset src="yyy.jar" and both xxx.jar and yyy.jar have the classes with the SAME fully-qualified class names. So the resulting jar file has duplicate class names. What are the possible implications of having duplicates?
谢谢.
推荐答案
如果它们是重复实现,则没有什么–加载哪个无关紧要.
If they're duplicate implementations, nothing–it wouldn't matter which is loaded.
否则,您将受类加载顺序的支配,并且可能会获得与您想要的不同的版本.
If not, you're at the mercy of class load order, and may get a different version than you want.
是指定将按列出的顺序搜索类路径条目(根据 这个类路径文档).但这仅在您完全控制类路径创建的情况下才有意义(例如,与在网络应用中不同).
It is specified that classpath entries will be searched in the order listed (as per this classpath doc). but that's only relevant if you're in complete control of classpath creation (unlike in a web app, for example).
(需要注意的是,类路径通配符会使顺序不确定.)
这篇关于在 java jar 中有重复的类有什么含义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!