I was able to get this done using jdeps. The usage is pretty simple:
jdeps <options> <classes...>
Where <classes> can be a pathname to a .class file, a directory, a JAR file,
or a fully-qualified class name.
Some of the options I found helpful in my case:
- -verbose:class: Print class-level dependencies excluding dependencies within the same package by default.
- -classpath <path>:Specify where to find class files.
- -package <pkgname>: Finds dependences matching the given package name (may be given multiple times)
- -regex <regex>: Finds dependences matching the given pattern
- -filter <regex>: Filter dependences matching the given pattern. If given multiple times, the last one will be used.
- -filter:package: Filter dependences within the same package (default)
- -filter:archive: Filter dependences within the same archive
- -filter:none: No- -filter:packageand- -filter:archivefiltering. Filtering specified via the -filter option still applies.
- -include <regex>: Restrict analysis to classes matching pattern. This option filters the list of classes to be analyzed.
- -recursive: Recursively traverse all dependencies.
Sample Usage for package com.abc.xyz.ui:
jdeps.exe -filter:archive -classpath <project_classpath> com\abc\xyz\ui\
Where <project_classpath> is the classpath of the project.
Output:
com.abc.xyz.ui (ui)
   -> com.itextpdf.text                                  itextpdf-5.5.12.jar
   -> org.apache.commons.io                              commons-io-2.6.jar
   -> org.apache.commons.lang3.time                      commons-lang3-3.8.1.jar
   -> org.apache.commons.text                            commons-text-1.6.jar
   -> org.controlsfx.control                             controlsfx-8.40.15.jar
   -> java.io
   -> java.lang
   -> java.net
   -> java.util
I used -filter ^java\..* option to exclude Java Runtime classes:
jdeps.exe -filter:archive -filter ^java\..* -classpath <project_classpath> com\abc\xyz\ui\
Output:
com.abc.xyz.ui (ui)
   -> com.itextpdf.text                                  itextpdf-5.5.12.jar
   -> org.apache.commons.io                              commons-io-2.6.jar
   -> org.apache.commons.lang3.time                      commons-lang3-3.8.1.jar
   -> org.apache.commons.text                            commons-text-1.6.jar
   -> org.controlsfx.control                             controlsfx-8.40.15.jar