java classpath中 jar包的顺序

举例说,

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

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

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

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

阅读 8.1k
1 个回答

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.

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题