简体   繁体   English

java -cp可以报告在可执行类中导入的每个包中找到的jar或类文件吗?

[英]Can `java -cp` report the jar or class file which it finds for each package imported in an executable class?

当使用java -cp path1:path2:path3 SomeClass执行一个类时,是否可以让java报告它为在该类中导入的每个包找到的jar或类文件名和路径名?

No ... and partly yes. 不...部分是。

No because "importing" is a compile time concept only. 不可以,因为“导入”只是一个编译时概念。 There is no need to import a class in order to use it, and an import statement doesn't actually mean that the class is actually used. 不需要为了使用它而import一个类,并且import语句实际上并不意味着该类已被实际使用。 Also, you don't import a package: you import classes from a package, or static members from a class. 另外,您不导入包:您从包中导入类,或者从类中导入静态成员。

Partly yes because the java -verbose:class option will log each class that gets loaded by the JVM. 部分原因是因为java -verbose:class选项将记录JVM加载的每个类。

And if you want to statically find all of the other classes that are directly referenced by a given class it is possible to get this by analyzing the classes .class file. 并且,如果您想静态查找给定类直接引用的所有其他类,则可以通过分析类.class文件来获取。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM