Complete PDF for the tutorial download
I tried to make a simple yet fun, including code examples and pictures tutorial about a hot and important topic which is JPMS(Java Platform Module System) which came in Java 9.
- Tutorial Contents
Highly based on java-9-new-features-in-simple-way-jshell-jpms-and-more and Jenkov Tutorials
Compile :
javac --module-source-path simple_module -d out1 -m moduleARun :
java --module-path out1 -m moduleA/pack1.MainCompile :
javac --module-source-path optional_module -d out2 -m moduleA,moduleBRun :
java --module-path out2 -m moduleB/pack2.MainBe careful not spaces are allowed between (moduleA,moduleB,moduleC)
Compile :
javac --module-source-path transitive_module -d out3 -m moduleA,moduleB,moduleCRun :
java --module-path out3 -m moduleC/pack3.MainCompile :
javac --module-source-path cyclic_module -d out4 -m moduleA,moduleBThis will produce the following error :
error: cyclic dependence involving moduleA requires moduleA;Compile :
javac --module-source-path qualified_module -d out5 -m exporterModule,moduleA,moduleBThe error:
error: package pack2 is not visible
import pack2.B;
^
(package pack2 is declared in module exporterModule, which does not export it to module moduleB)
1 errorHow to solve : Well as we can see that error happens because inside our exporterModule we allow access to pack2 only for moduleA :
Do you want to fix it ?
Simply export pack2 for moduleB also like this :
export pack2 to moduleA,moduleB;Okay but now how to run sir ?
java --module-path out5 -m moduleA/pack1.Test java --module-path out5 -m moduleB/pack1.TestCompile :
//TODORun :
//TODOCompile :
javac --module-source-path aggregator_module -d out7 -m aggregator,moduleA,moduleB,moduleC,useModuleRun :
java --module-path out7 -m useModule/pack4.MainCompile :
javac --module-source-path name_conflicts_module -d out9 -m moduleA,moduleB,useModuleThis will produce the following error :
error: module useModule reads package pack1 from both moduleA and moduleB
module useModule{
^
1 errorCompile :
javac --java-module-path resolution_process_module -d out10 -m useModule,moduleA,moduleB,moduleC,moduleDRun :
java --module-path out10 --show-module-resolution -m useModule















































