首页 > java classpath中 jar包的顺序

java classpath中 jar包的顺序

举例说,

a.jar, b.jar 都有 MyTest这个类。

java -cp a.jar;b.jar ...

那么 这个MyTest 拿到的到底 是哪个jar包的?

经验表明 是cp前面的那个, 但没看到任何官方文档 描述这个。


ok, 找到了。

https://docs.oracle.com/javase/8/docs/technotes/tools/unix/classpath.html

Specification Order

The order in which you specify multiple class path entries is
important. The Java interpreter will look for classes in the
directories in the order they appear in the class path variable. In
the previous example, the Java interpreter will first look for a
needed class in the directory /java/MyClasses. Only when it does not
find a class with the proper name in that directory will the
interpreter look in the /java/OtherClasses directory.

【热门文章】
【热门文章】