Java 9 Modules: Difference between revisions
No edit summary |
No edit summary |
||
Line 2: | Line 2: | ||
* https://www.baeldung.com/java-9-modularity | * https://www.baeldung.com/java-9-modularity | ||
* https://www.oracle.com/corporate/features/understanding-java-9-modules.html | * https://www.oracle.com/corporate/features/understanding-java-9-modules.html | ||
* | * https://www.infoq.com/presentations/java-9-modules | ||
=Internal= | =Internal= | ||
* [[Java#Java9|Java]] | * [[Java#Java9|Java]] | ||
=Concepts= | =Concepts= |
Revision as of 21:19, 18 May 2021
External
- https://www.baeldung.com/java-9-modularity
- https://www.oracle.com/corporate/features/understanding-java-9-modules.html
- https://www.infoq.com/presentations/java-9-modules
Internal
Concepts
Module
A module is a JAR with a module descriptor, available to the JVM on the module path.
Module Types
Named Module
Unnamed Module
The "unnamed" module contains code compiled without a module-info.java descriptor.
Automatic Module
For JARs created before Java 9, code will get a module name derived from the JAR file name.
Modulepath
All the code on the modulepath lives in their own "named" modules. Named modules are only found via the modulepath.
The JRE is always on the modulepath, so its internal code cannot be accessed from code on the classpath.
Package Relationship to Modules
A package can only be accessed from one module. Hierarchical packages are treated as separate, so "java.util" and "java.util.logging" can exist in different modules. Only public fields and methods are accessible in the code of exported packages of other modules.
Classpath
All the code from classpath lives together in the "unnamed" module.
module-info.java
module-info.java
is file that represents a module descriptor.
If code is compiled without a module-info.java
, the code will be part of the "unnamed" module and can see all other code in the "unnamed", java.base
and modules in the java.se
root module. That means if no module-info.java
is present in the project, everything should still work as in Java 8. Dependencies should be put on the classpath, not on modulepath.
If the code is compiled with a module-info.java
, the code will become part of its own named module, and can only see code in java.base
and other named modules with are referenced with requires
in module-info.java
.
Organizatorium
- Classpath and module path is mutually exclusive.