When using java -cp path1:path2:path3 SomeClass
to execute a class, is it possible to make java
report the jar or class filename and pathname which it finds for each package imported in the class?
Asked
Active
Viewed 40 times
0
-
I believe you need to use the `-verbose` option, see https://stackoverflow.com/questions/10230279/java-verbose-class-loading – Olivier Gérardin Apr 12 '19 at 12:05
1 Answers
1
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. 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.
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.

Stephen C
- 698,415
- 94
- 811
- 1,216