0

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
Tim
  • 1
  • 141
  • 372
  • 590

1 Answers1

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