jdeps
Analyze Java class dependencies
TLDR
Analyze the dependencies of a .jar or .class file
Print a summary of all dependencies of a specific .jar file
Print all class-level dependencies of a .jar file
Output the results of the analysis in a DOT file into a specific directory
Display help
SYNOPSIS
jdeps [options] <path_to_classes_or_jars>
jdeps [options] [<classes|jars|directories>]
PARAMETERS
--module-path <path> or -p <path>
Specifies the module path for resolving modules.
--summary or -s
Prints only the summary of dependencies.
--verbose or -v
Prints all class-level dependencies, including platform dependencies.
--recursive or -r
Recursively traverses dependencies.
--apionly
Shows only dependencies on API classes.
--check <module-name>
Checks dependencies of a specific module.
--multi-release <version>
Specifies the version for analyzing multi-release JARs.
--list-deps
Lists class-level dependencies.
--ignore-missing-deps
Continues processing even if some dependencies are missing.
--module <module-name>
Specifies a module to analyze its dependencies.
--system <jdk|all>
Specifies which system modules to include.
--dot-output <dir>
Generates a DOT file for dependencies in the specified directory, visualizable with tools like Graphviz.
DESCRIPTION
jdeps is a powerful command-line utility provided with the Java Development Kit (JDK) designed to analyze Java class file dependencies. Its primary purpose is to help developers understand the static dependencies of their Java applications and libraries. This includes identifying dependencies on specific packages, classes, and crucially, on internal JDK APIs (like sun.* packages) that are not part of the stable Java SE specification and may be subject to removal or change in future Java versions. jdeps is instrumental in migrating applications to newer Java versions, especially when adopting the Java Platform Module System (JPMS) introduced in Java 9. It can analyze .class files, JAR files, or directories containing compiled Java code, providing insights into which Java SE modules an application explicitly or implicitly requires.
CAVEATS
jdeps operates on compiled bytecode; it does not analyze Java source files directly. For very large applications, the default output can be extremely verbose, requiring careful use of filtering options like --filter, --include, or --exclude. Its accuracy relies on the complete and correct specification of the class path or module path where dependent classes and JARs reside. It requires a Java Development Kit (JDK) environment to execute, as it's not typically found in a Java Runtime Environment (JRE) distribution.
INTERNAL API IDENTIFICATION
One of the most critical uses of jdeps is to identify dependencies on internal, non-standard APIs (e.g., those in sun.* or com.sun.* packages). Using such APIs can lead to compatibility issues across different JDK versions, as they are not guaranteed to be stable or even present.
JPMS MIGRATION AID
jdeps is a key tool for migrating existing applications to the Java Platform Module System. It can help determine the required modules for a given set of JARs, identify split packages, and highlight cyclic dependencies, all of which are crucial steps in modularizing a legacy application.
DOT GRAPH GENERATION
The --dot-output <dir> option allows jdeps to generate a DOT file, which can then be visualized using tools like Graphviz. This provides a graphical representation of the dependencies, making complex relationships easier to understand.
HISTORY
jdeps was first introduced as a developer preview tool in JDK 8, emerging from Project Jigsaw's efforts to modularize the Java platform. Its capabilities were significantly expanded and solidified with the official release of the Java Platform Module System (JPMS) in JDK 9. Since then, it has become an indispensable utility for analyzing module dependencies, identifying internal API usage, and preparing applications for modular deployment, reflecting the ongoing evolution towards a more modular Java ecosystem.