Module là tập hợp có tên, tự mô tả của code và data. Code tổ chức thành các package chứa class/interface. Data bao gồm resource và thông tin tĩnh. Khai báo module bằng file module-info.java tại gốc source code.
Mẫu module-info.java
module <module-name> {
requires <module-name1>;
requires <module-name2>;
exports <package-name1>;
exports <package-name2>;
exports <package-name> to <module-name>;
}
Có thể dùng các tùy chọn dòng lệnh để sửa đổi module hiện có, thêm dependency, export package thêm.
Các lệnh sửa đổi module
1) --add-reads <module>=<target-module>(,<target-module>)*
Cập nhật <module> để đọc <target-module>, bất kể khai báo module. <target-module> có thể là ALL-UNNAMED để đọc tất cả module vô danh.
2) --add-exports <module>/<package>=<target-module>(,<target-module>)*
Cập nhật <module> để export <package> đến <target-module>. ALL-UNNAMED để export đến tất cả module vô danh.
3) --add-opens <module>/<package>=<target-module>(,<target-module>)*
Cập nhật <module> để mở <package> cho <target-module> (cho phép reflection sâu).
4) --patch-module <module>=<file>(;<file>)*
Thay thế hoặc bổ sung module với class/resource từ file JAR hoặc thư mục.