24 Nisan 2018 Salı

Java 9 module tanımı

Modüller Nerede
Modüller JRE-9/lib/modules dizini altında. Açıklaması şöyle.
The modules file is a container file. It's internal to the JDK and the format is not documented (it may change at any time). For troubleshooting purposes, the jimage tool in the bin directory can be used to list or extract the contents
Açıklaması şöyle.
The modules file is meant to be a single file (not meant to be extracted anywhere) which contains a binary representation of all of the modules present in the JDK in an undocument format which is subject to change. You can list the modules it contains with java --list-modules.
Modül Nedir
Açıklaması şöyle.
At a high-level, the module system is not dynamic in the sense that individual modules can not be unloaded or replaced in a running VM. However, you can use the API, specifically java.lang.module.Configuration and java.lang.ModuleLayer to create dynamic configurations of modules and instantiate them in a running VM as a layer of modules. 
Automatic Module Nedir
Açıklaması şöyle
The module system creates a module from every JAR it finds on the module path. For modular JARs (i.e. those with module descriptors) that is straightforward as they define the module's properties (name, requires, exports). For plain JARs (no module descriptor) this approach doesn't work, so what should the module system do instead? It automatically creates a module - an automatic module, so to speak - and takes the most safe guesses for the three properties.
Modular JAR File Nedir
Açıklaması şöyle
A modular JAR file is like an ordinary JAR file in all possible ways, except that it also includes a module-info.class file in its root directory.
static özelliği
Açıklaması şöyle. Sadece derlemen esnasında belirtilen modul'e olan bağımlılık kontrol edilir. Çalışma esnasında edilmez.
The dependence is mandatory in the static phase, during compilation, but is optional in the dynamic phase, during execution.
Şöyle yaparız.
module bar {
  requires java.compiler;
  requires static java.base;
Şöyle yaparız.
requires java.transaction;
requires java.persistence;
requires java.sql;
requires java.naming;
transitive özelliği
Benim bağımlılıklarımın beni kullanan modüllere de geçmesini sağlar. Eğer bunu tanımlamazsam benim bağımlılıklarımın da beni kullanan modüllerce tanımlanması gerekir. Elimizde şöyle bir bağımlılık olsun.
module foo {
  requires java.base;
  requires transitive java.compiler;
foo modülünü kullanan her modül java.compiler'a erişebilir. Ancak java.base'e de erişmek isterse şöyle yapması gerekir.
module bar {
  requires foo; // java.compiler is available to read
  requires java.base; // still required
Açıklaması şöyle
A 'requires' directive (irrespective of 'transitive') expresses that one module depends on some other module. The effect of the 'transitive' modifier is to cause additional modules to also depend on the other module. If module M 'requires transitive N', then not only does M depend on N, but any module that depends on M also depends on N. This allows M to be refactored so that some or all of its content can be moved to a new module N without breaking modules that have a 'requires M' directive.

Hiç yorum yok:

Yorum Gönder