- Java 9 Dependency Injection
- Krunal Patel Nilang Patel
- 287字
- 2021-08-27 18:49:57
Module types
There are different types of modules:
Named application modules: This is a simple module that we can all create. Any third-party libraries can be application modules.
Platform modules: As we have seen, JDK 9 itself migrated to modular architecture. All the existing features will be provided as different modules, such as java.sql, java. desktop, java.transaction. These are called Platform Modules. All modules are implicitly dependent on the java.base module.
Automatic modules: A pre-Java 9 JAR, which is not migrated to modules, can be placed in a module path without module descriptors. These are called automated modules. This JAR implicitly exports all their packages for other modules and also reads other modules along with unnamed modules. Because there is no unique name for an automatic module, JDK generates depending on the JAR filename by removing the version number and extension. For example, the file postgresql-42.1.4.jar as a module will be postgresql.
Unnamed modules: JDK 9 does not remove classpaths. So all the JARs and classes placed on the class path are called Unnamed Modules. These modules can read all the modules and export all the packages, as they do not have a name. This module cannot be read or required by named application modules.
In JDK 9, we have two module paths and class paths. Now we might ask which JAR goes where? So, the answer is, a modular jar with an application module goes into --module-path, and a modular jar with an unnamed module can be placed into --class-path. Similarly, a non-modular jar can be migrated into an automatic module and goes into --module-path. If a jar contains an unnamed module, then it resides in --class-path.