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 ...>
PARAMETERS
-apionly
Analyze API classes only.
-classpath <path>
Specify where to find user class files.
-cp <path>
Equivalent to -classpath.
-dotdir <dir>
Specify the directory to write generated dot files.
-filter <regex>
Filter dependencies matching the given regular expression.
-jdkinternals
Show dependencies to JDK internal APIs.
-m <module>
Analyze the dependencies of the specified module.
-multi-release <version>
Process multi-release JAR files.
-q
Suppress the output of summary information.
-s
Summarize dependencies by package.
-verbose
Enable verbose output.
-version
Print the version information.
-help
Display help information.
-modulepath <path>
Specify where to find application modules.
-p <package>
Analyze the dependencies of the specified package.
-R
Recursively traverse directories and JAR files.
-require <module>
Analyze the dependencies of modules required by the specified module.
--generate-module-info <dir>
Generates a module-info.java file.
DESCRIPTION
jdeps is a command-line tool for analyzing class files. It shows the dependencies of Java class files. You can use it to find missing dependencies, circular dependencies, and generally understand the dependencies between classes and packages in your Java application.
jdeps analyzes a Java application and produces a graph showing the package-level or class-level dependencies. It can be used to understand the structure of a codebase, identify potential refactoring opportunities, and pinpoint missing modules or JAR files required for execution. It's useful for preparing for the modularization of existing applications and identifying dependencies that need to be resolved. The output can be customized in various ways to focus on specific aspects of the dependency graph. For example, you can filter output by module, package, or class, and you can output the results in different formats, such as text or Graphviz dot format.
It helps to discover implicit or undocumented dependencies that might exist. It is useful to identify potential problems before deploying applications, especially with the evolution of the Java platform and its module system.
CAVEATS
jdeps might not be able to identify all dependencies, especially those that are dynamically loaded or use reflection. Accuracy depends on the completeness and correctness of the classpaths provided.
When analyzing large applications, jdeps can consume significant memory and time. Consider using filtering options to narrow down the scope of analysis.
OUTPUT FORMATS
jdeps can output dependencies in several formats: Plain Text (default), Graphviz Dot format for visualization, or in a summary format. The appropriate format depends on the desired level of detail and how the results are to be used. Dot format can be used with tools like Graphviz to generate visual dependency graphs.
MODULE SYSTEM INTEGRATION
jdeps plays a crucial role in migrating applications to the Java module system. It helps identify dependencies that need to be explicitly declared in module-info.java files. By analyzing the class dependencies, developers can ensure that all required modules are declared as dependencies, thereby preventing runtime errors and ensuring proper module encapsulation.
HISTORY
jdeps was introduced as part of JDK 8 and has been enhanced in subsequent releases to support new Java features, such as modules (Java 9+). Its primary purpose is to facilitate understanding and managing dependencies within Java applications, especially as applications evolve towards a more modular architecture.
SEE ALSO
jlink(1), jmod(1), jar(1)