Of particular importance, and much consternation, the class loader will load classes in the order they appear in the classpath. Starting with the first classpath entry, the class loader visits each specified directory or archive file attempting to find the class to load. The first class it finds with the proper name is loaded, and any remaining classpath entries are ignored.
Sounds simple, right?
載自:http://www.javaworld.com/javaworld/javatips/jw-javatip105.html
上面说明了,java xx -classpath ".;a.jar;b.jar;" 时,如果a.jar和b.jar有重名的类,那么会以a.jar的为准,忽略b.jar的,因为jvm按照-classpath参数的路径先后顺序去load类,后续加载的同名的类会被忽略。
本文详细解释了类加载器如何按照class路径顺序加载类,并指出在classpath中重复类名的情况下,后加载的类将被忽略。通过实例演示了这种行为在实际开发中的应用。
531

被折叠的 条评论
为什么被折叠?



