在 java jar 中有重复的类有什么影响? [英] What are the implications of having duplicate classes in java jar?

查看:29
本文介绍了在 java jar 中有重复的类有什么影响?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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 中有重复的类有什么影响?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆