How can I get list of all modules in current JVM instance via Java code? Is it possible? If yes, then how?
java. base is known as the "mother of Java 9 modules." In the following image, you can see the modular aspects of the system and can probably make the leap to understand how a modularized JDK means that you can also modularize your own applications. This is only a few of the 98 platform modules.
xml files and the Maven directory project structure. The module descriptor ( module-info. java ) needs to be located in the src/main/java directory.
A module descriptor is the compiled version of a module declaration that's defined in a file named module-info. java . Each module declaration begins with the keyword module , followed by a unique module name and a module body enclosed in braces, as in: A key motivation of the module system is strong encapsulation.
These modules are split into four major groups: java, javafx, jdk, and Oracle. java modules are the implementation classes for the core SE Language Specification. javafx modules are the FX UI libraries. Anything needed by the JDK itself is kept in the jdk modules.
ModuleLayer.boot().modules().stream()
.map(Module::getName)
.forEach(System.out::println);
Using a jar or directory of modules as an input for your application, you can possibly use a ModuleFinder
to start off with and further making use of the findAll
to find the set of all module references that this finder can locate.
Path dir1, dir2, dir3;
ModuleFinder finder = ModuleFinder.of(dir1, dir2, dir3);
Set<ModuleReference> moduleReferences = finder.findAll();
This is easily possible with the command line option to list the modules as:
java -p <jarfile> --list-modules
which should be sufficient though, if you do not want to intentionally get into tweaking things with the ModuleLayer
and the Configuration
of the java.lang.module
as pointed out precisely by @Alan's answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With