What are automatic modules in Java 9?
An automatic module is a jar that we put on the modulepath. There is a number of pre-existing libraries that can be used in our applications, and many of these are not yet modularized. To facilitate migration, we can add any library’s jar file to an application’s module path, then use packages in that jar file. It can implicitly become an automatic module and can be specified in the module declaration’s requires directive. The jar’s filename becomes its module name that must be a valid Java identifier that can be used in "requires" directive.
An automatic module:
- Implicitly exports all package types, so any module that can read an automatic module (including unnamed module) has to access public types in automatic module packages.
- Implicitly reads (requires) all other modules, including other automatic modules, and the unnamed module, so an automatic module has access to all public types exposed by the system’s other modules.
%JAVA_HOME%\java --module-path ./libs:./libs-legacy --module app/com.app.Main
Naming of Automatic Module:
- The extension “.jar” is deleted.
- The version number is removed. For instance: mylib-1.2.3 -> mylib
- Non-alphanumeric characters are replaced by periods.
- Repetitive points are replaced by a single point, the points at the start and end of the chain are deleted.
Published on 07-Apr-2020 15:52:23