https://github.com/goxr3plus/java9-modules-tutorial
:new: ( Simple Module , Optional , Transitive , Cyclic , Qualified Exports , Module Graph , Observable , Aggregator , Package Naming Conflicts , Module Resolution Process )
https://github.com/goxr3plus/java9-modules-tutorial
java11 java9-jigsaw java9module
Last synced: about 2 months ago
JSON representation
:new: ( Simple Module , Optional , Transitive , Cyclic , Qualified Exports , Module Graph , Observable , Aggregator , Package Naming Conflicts , Module Resolution Process )
- Host: GitHub
- URL: https://github.com/goxr3plus/java9-modules-tutorial
- Owner: goxr3plus
- Created: 2019-06-04T13:49:48.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-02-17T10:58:49.000Z (almost 6 years ago)
- Last Synced: 2025-03-24T14:44:15.786Z (9 months ago)
- Topics: java11, java9-jigsaw, java9module
- Language: Java
- Homepage: https://www.udemy.com/java-9-new-features-in-simple-way-jshell-jpms-and-more/
- Size: 90.8 KB
- Stars: 8
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
# Java 9 ++ modules full tutorial
#### Everything is tested with JDK 11.0.3

### Complete PDF for the tutorial [download](https://github.com/goxr3plus/java9-modules-tutorial/files/3256292/JPMS.PDF)
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**](https://en.wikipedia.org/wiki/Java_Platform_Module_System)) which came in Java 9.
- **Tutorial Contents**
- [**Simple module**](#1)
- [**Optional**](#2)
- [**Transitive**](#3)
- [**Cyclic**](#4)
- [**Qualified Exports**](#5)
- [**Observable**](#6)
- [**Aggregator**](#7)
- [**Module Graph**](#8)
- [**Package Naming Conflicts**](#9)
- [**Module Resolution Process**](#10)
Highly based on [ java-9-new-features-in-simple-way-jshell-jpms-and-more ](https://www.udemy.com/java-9-new-features-in-simple-way-jshell-jpms-and-more/) and [Jenkov Tutorials](http://tutorials.jenkov.com/java/modules.html)


---

---
# 1. ------------------- Simple module -------------------



##### Ps i have provided all the code in folders so you don't have to manually type it ;
Compile :
``` JAVA
javac --module-source-path simple_module -d out1 -m moduleA
```
Run :
``` JAVA
java --module-path out1 -m moduleA/pack1.Main
```
---
# 2. ------------------- Optional -------------------





Compile :
``` JAVA
javac --module-source-path optional_module -d out2 -m moduleA,moduleB
```
Run :
``` JAVA
java --module-path out2 -m moduleB/pack2.Main
```
---
# 3. ------------------- Transitive -------------------



**Be careful not spaces are allowed between (moduleA,moduleB,moduleC)**
Compile :
``` JAVA
javac --module-source-path transitive_module -d out3 -m moduleA,moduleB,moduleC
```
Run :
``` JAVA
java --module-path out3 -m moduleC/pack3.Main
```
---
# 4. ------------------- Cyclic -------------------



Compile :
``` JAVA
javac --module-source-path cyclic_module -d out4 -m moduleA,moduleB
```
This will produce the following error :
``` JAVA
error: cyclic dependence involving moduleA requires moduleA;
```

---
# 5. ------------------- Qualified Exports-------------------



Compile :
``` JAVA
javac --module-source-path qualified_module -d out5 -m exporterModule,moduleA,moduleB
```
The error:
``` JAVA
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 error
```
How 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 :
``` JAVA
export pack2 to moduleA,moduleB;
```
Okay but now how to run sir ?
``` JAVA
java --module-path out5 -m moduleA/pack1.Test
```
``` JAVA
java --module-path out5 -m moduleB/pack1.Test
```
---
# 6. ------------------- Observable -------------------

Compile :
``` JAVA
//TODO
```
Run :
``` JAVA
//TODO
```
---
# 7. ------------------- Aggregator -------------------







Compile :
``` JAVA
javac --module-source-path aggregator_module -d out7 -m aggregator,moduleA,moduleB,moduleC,useModule
```
Run :
``` JAVA
java --module-path out7 -m useModule/pack4.Main
```
---
# 8. ------------------- Module Graph -------------------








---
# 9. ------------ Package Naming Conflicts ------------




Compile :
``` JAVA
javac --module-source-path name_conflicts_module -d out9 -m moduleA,moduleB,useModule
```
This will produce the following error :
``` JAVA
error: module useModule reads package pack1 from both moduleA and moduleB
module useModule{
^
1 error
```
---
# 10. ------------ Module Resolution Process ------------






Compile :
``` JAVA
javac --java-module-path resolution_process_module -d out10 -m useModule,moduleA,moduleB,moduleC,moduleD
```
Run :
``` JAVA
java --module-path out10 --show-module-resolution -m useModule
```