Jdeps tool analyzes class and module dependencies.
You can launch jdeps
using below command. A path can be a class file, directory or .jar file.
Jdeps [options] path . . .
From Java 9 jdeps
has been improved to support modules relevant operations such as listing dependency modules, generating module info descriptor, describing the summary of the module etc.
Let’s create a simple java 8 application and try to generate module info descriptor.
Build the project and generate the jar file.
After building the project we have out/production folder generated with class files. Let’s generate jar file.
jar -c -f <path>/filname.jar -C <class files location> .
jar -c -f out/app.jar -C out/production/java8deps .
Now, app.jar is generated. Let’s run some jdeps
commands.
Jdeps -s <path>
Using jdeps you can analyze the dependencies.
jdeps <path>
3. List dependencies
jdeps --list-deps <path>
Lists all the application dependencies along with platform dependencies (java.*, jdk.*
). By default entire application considered as part of unnamed module. The same can be observed below under command jdeps --list-deps.
4. List reduced dependencies
jdeps --list-reduced-deps <path>
Same as --list-deps
but doesn’t display implied dependencies. For instance, If module M1 depends on M2 and M3, M2 requires public on M3, then M1 reading M3 is implied and removed from the module graph. Hence java.base is ignored when ran jdeps
with reduced deps.
5. Generate module info descriptor
jdeps --generate-module-info <path>
Post running jdeps --generate-module-info
on app.jar it generates module descriptor (module-info.java
) with required dependencies.
The generated module-info.java
looks as follows. The ‘exports’ statements are not required unless some other module depends on the current module.