Java 11 Cookbook
上QQ阅读APP看书,第一时间看更新

How it works...

The jdeps command is a static-class dependency analyzer and is used to analyze the static dependencies of the application and its libraries. The jdeps command, by default, shows the package-level dependencies of the input files, which can be .class files, a directory, or a JAR file. This is configurable and can be changed to show class-level dependencies. There are multiple options available to filter out the dependencies and to specify the class files to be analyzed. We have seen a regular use of the -cp command-line option. This option is used to provide the locations to search for the analyzed code's dependencies. 

We have analyzed the class file, JAR files, and the JDK modules, and we also tried out different options of the jdeps command. There are a few options, such as -e, -regex, --regex, -f, --filter, and -include, which accept a regular expression (regex). It's important to understand the output of the jdeps command. There are two parts of information for every class/JAR file being analyzed:

  1. The summary of the dependency for the analyzed file (JAR or class file). This consists of the name of the class or the JAR file on the left and the name of the dependent entity on the right. The dependent entity can be a directory, a JAR file, or a JDK module, as follows:
      Sample.class -> classes
      Sample.class -> lib/jackson-core-2.9.6.jar
      Sample.class -> lib/jackson-databind-2.9.6.jar
      Sample.class -> java.base
      Sample.class -> jdk.unsupported

  1. A more verbose dependency information of the contents of the analyzed file at the package or class level (depending on the command-line options). This consists of three columns—column 1 contains the name of the package/class, column 2 contains the name of the dependent package, and column 3 contains the name of the module/JAR where the dependency is found. A sample output looks like the following:
      com.packt  -> com.fasterxml.jackson.core.type  
jackson-core-2.9.6.jar com.packt -> com.fasterxml.jackson.databind
jackson-databind-2.9.6.jar com.packt -> com.packt.model sample.jar