Search code examples
javajava-9java-modulejava-platform-module-systemmodule-info

List the modules resolved during the application startup


How can one get to know of the list of modules that have been resolved while the application has been started so as to figure out what all service providers are accessible from the root module.


Solution

  • Module Resolution

    The module resolution is a two-step process.

    • The first step recursively enumerates the 'requires' directives of a set of root modules.
    • If all the enumerated modules are observable, then the second step computes their readability graph. The readability graph embodies how modules depend on each other, which in turn controls access across module boundaries.

    One can make use of the debugging flag as mentioned in the java tool documentation by means of a VM argument :

    --show-module-resolution
    

    Shows module resolution output during startup.

    For example, the option would list out :

    • root module
    • all the modules required and resolved by the root module
    • further bindings used by the above-required modules and
    • successive modules resolved during startup

    On running the following command:

    Jigsaw git:(master) ✗ ../jdk-9.0.1.jdk/Contents/Home/bin/java 
                           --show-module-resolution 
                           -p ../out/production/100DaysOfJava9 
                           -m HundredDaysOfJavaNine/com.stackoverflow.nullpointer.Challenge1
    

    It results in the following:-

    root HundredDaysOfJavaNine file:///.../out/production/100DaysOfJava9/
    
    HundredDaysOfJavaNine requires jdk.incubator.httpclient jrt:/jdk.incubator.httpclient
    
    java.base binds jdk.localedata jrt:/jdk.localedata
    java.base binds java.security.jgss jrt:/java.security.jgss
    java.base binds java.logging jrt:/java.logging
    java.base binds jdk.javadoc jrt:/jdk.javadoc
    java.base binds jdk.jartool jrt:/jdk.jartool
    java.base binds jdk.jlink jrt:/jdk.jlink
    java.base binds jdk.compiler jrt:/jdk.compiler
    java.base binds jdk.jdeps jrt:/jdk.jdeps
    java.base binds java.desktop jrt:/java.desktop
    java.base binds jdk.zipfs jrt:/jdk.zipfs
    ...