Java - 如何找出导入来自哪个Jar文件?

Gre*_*reg 14 java netbeans jar

我正在处理的项目有大约10个jar文件作为库.在其中一个文件的顶部有一个导入语句,如:

import jpe.nar.crat.maker.ObjectMakerFactory;
Run Code Online (Sandbox Code Playgroud)

有没有办法告诉它来自哪个Jar文件?

(如果重要,我正在使用Netbeans.)

Bal*_*usC 14

你可以用CodeSource#getLocation()它.该CodeSource可通过ProtectionDomain#getCodeSource().该ProtectionDomain又是通过提供Class#getProtectionDomain().

URL location = ObjectMakerFactory.class.getProtectionDomain().getCodeSource().getLocation();
System.out.println(location.getPath());
// ...
Run Code Online (Sandbox Code Playgroud)